Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell alias calling non-existent command returns 0 exit code #1800

Open
brycegbrazen opened this issue Jul 23, 2024 · 1 comment
Open
Labels
bug os:windows Windows-specific shell Shell related issues

Comments

@brycegbrazen
Copy link
Contributor

brycegbrazen commented Jul 23, 2024

Running an alias using the Powershell shell plugin with rez-env doesn't return a failure exit code when attempting to run a non-existent aliased command in-line.

Environment

  • Windows 10
  • Rez 2.112.0
  • Rez python version 3.7.9

To Reproduce

  1. Create a package.py for a test_invalid_alias package with the following definition:
name = "test_invalid_alias"

version = "1.0.0"

build_command = ""

def commands():
    alias('my_alias', 'a_non_existent_executable')
  1. Install the package to your package repository.
  2. Run rez-env -- a_non_existent_executable
  3. Observe the following error message:
& : The term 'a_non_existent_executable' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\bryce.gattis\AppData\Local\Temp\rez_context_2bfjto0k\rez-shell.ps1:4 char:3
+ & a_non_existent_executable
+   ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (a_non_existent_executable:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
  1. Run rez-env test_invalid_alias -- my_alias
  2. Observe $LASTEXITCODE as being 0 instead of a non-zero exit code.

Use Case
This is currently happening and causing issues on our render farm. With Rez, we are creating aliases for python that map to whatever the DCC's version of python is. For example, the python alias for Houdini maps to hython.

The behavior observed via this issue is problematic when a specific machine doesn't have the correct version of Houdini installed on their machine. Rez will still use the alias (and expect that the corresponding software is installed where the Rez package is looking for it), but will not correctly return a non-zero exit code if the executable is not found.

This causes false positives on our render farm.

Related Issues/PRs

Expected behavior
A non-zero exit code is returned.

Actual behavior
A 0 exit code is returned.

@dbr
Copy link
Contributor

dbr commented Aug 8, 2024

I had similar problem exposing commands like nuke as an alias for Nuke15.0 etc

The aliases don't seem to propagate any error codes (so even if the command starts, but say it fails mid-render - then farm monitoring software doesn't notice the job failed)

I ended up replacing all aliases with .bat scripts, e.g our nuke.bat contains:

@echo off
"%~dp0\nuke\Nuke15.0.exe" %*

and so on, and these get added to $PATH instead of using Rez's alias(...)

Wrapper scripts like this are slightly less convenient to setup, but they seem a lot more robust - e.g even in bash, aliases have some weird properties which makes them a flaky solution for this problem (mainly they don't get inherited into child shells - so if you did rez env mypackagewithanalias -- my_alias would work but rez env mypackagewithanalias -- bash -c 'myalias' would fail)

@JeanChristopheMorinPerso JeanChristopheMorinPerso added os:windows Windows-specific shell Shell related issues labels Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug os:windows Windows-specific shell Shell related issues
Projects
None yet
Development

No branches or pull requests

3 participants