Fix PowerShell command failure status#2109
Conversation
Signed-off-by: snoopuppy582 <mnb0968@naver.com>
|
|
|
@snoopuppy582 was this issue tackled as part of devdays, or independently? Thank you. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2109 +/- ##
==========================================
- Coverage 60.65% 60.64% -0.01%
==========================================
Files 164 164
Lines 20584 20584
Branches 3579 3579
==========================================
- Hits 12485 12483 -2
- Misses 7224 7225 +1
- Partials 875 876 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This was independent. I saw #2073, reproduced the PowerShell status issue locally on Windows, and opened the PR with the focused regression test for that case. Thanks for checking. |
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect exit-status propagation for PowerShell startup scripts generated by Rez, specifically when a PowerShell command fails before $LASTEXITCODE is set (eg, “command not found”), by preserving the pre-check $? state and adding a Windows regression test to lock in the behavior.
Changes:
- Preserve
$?in generated PowerShell startup scripts before probingLASTEXITCODE, avoiding$?being overwritten byTest-Path. - Ensure a failing PowerShell command that doesn’t set
LASTEXITCODEresults in process exit code1. - Add a Windows-only regression test covering missing-command failures for both
powershellandpwsh.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/rezplugins/shell/_utils/powershell_base.py |
Captures $? before Test-Path variable:LASTEXITCODE to reliably map PowerShell failures to non-zero exit codes. |
src/rez/tests/test_shells.py |
Adds a Windows regression test asserting missing PowerShell commands return exit code 1 for both powershell and pwsh. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
$?before checkingLASTEXITCODEin generated PowerShell startup scriptsLASTEXITCODEpowershellandpwshTest plan
pytest src/rez/tests/test_shells.py::TestShells::test_powershell_command_not_found_returncode -qpytest src/rez/tests/test_shells.py::TestShells::test_pwsh_lastexitcode_gui -qflake8 src/rezplugins/shell/_utils/powershell_base.py src/rez/tests/test_shells.pyexecute_shellcheck: missing command returns 1 forpowershellandpwsh;hello_world -q -r 66still returns 66 for bothCloses #2073