diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py index 114497089..a05688730 100644 --- a/src/rez/tests/test_shells.py +++ b/src/rez/tests/test_shells.py @@ -607,6 +607,22 @@ def _make_alias(ex): out, _ = p.communicate() self.assertEqual(1, p.returncode) + @per_available_shell() + def test_alias_non_existent_command_return_code(self, shell): + """Ensure return codes are correct while using aliases.""" + config.override("default_shell", shell) + + def _make_alias(ex): + ex.alias('my_alias', 'a_non_existent_executable') + + r = self._create_context([]) + p = r.execute_shell(command='my_alias', + actions_callback=_make_alias, + stdout=subprocess.PIPE) + + out, _ = p.communicate() + self.assertNotEqual(0, p.returncode) + if __name__ == '__main__': unittest.main() diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index 89074efef..e9252f9bf 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -153,7 +153,7 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False): # only the bool $? var is set. # executor.command( - "if(! $? -or $LASTEXITCODE) {\n" + "if(! $? -or $LASTEXITCODE -or $error) {\n" " if ($LASTEXITCODE) {\n" " exit $LASTEXITCODE\n" " }\n" @@ -248,7 +248,7 @@ def prependenv(self, key, value): # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. self._addline( - 'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value)' + 'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem -ErrorAction Ignore "Env:{0}").Value)' .format(key, value, self.pathsep) ) @@ -257,15 +257,15 @@ def appendenv(self, key, value): # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. - # The nested Get-ChildItem call is set to SilentlyContinue to prevent + # The nested Get-ChildItem call is set to Ignore to prevent # an exception of the Environment Variable is not set already self._addline( - 'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value + "{1}{2}")' + 'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction Ignore "Env:{0}").Value + "{1}{2}")' .format(key, os.path.pathsep, value)) def unsetenv(self, key): self._addline( - 'Remove-Item -ErrorAction SilentlyContinue "Env:{0}"'.format(key) + 'Remove-Item -ErrorAction Ignore "Env:{0}"'.format(key) ) def resetenv(self, key, value, friends=None):