Skip to content

Fix PowerShell command failure status#2109

Open
snoopuppy582 wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
snoopuppy582:fix/powershell-command-status
Open

Fix PowerShell command failure status#2109
snoopuppy582 wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
snoopuppy582:fix/powershell-command-status

Conversation

@snoopuppy582
Copy link
Copy Markdown

Summary

  • preserve $? before checking LASTEXITCODE in generated PowerShell startup scripts
  • return exit code 1 when a PowerShell command fails before setting LASTEXITCODE
  • add a Windows regression test for missing-command failures in both powershell and pwsh

Test plan

  • pytest src/rez/tests/test_shells.py::TestShells::test_powershell_command_not_found_returncode -q
  • pytest src/rez/tests/test_shells.py::TestShells::test_pwsh_lastexitcode_gui -q
  • flake8 src/rezplugins/shell/_utils/powershell_base.py src/rez/tests/test_shells.py
  • manual execute_shell check: missing command returns 1 for powershell and pwsh; hello_world -q -r 66 still returns 66 for both

Closes #2073

Signed-off-by: snoopuppy582 <mnb0968@naver.com>
@snoopuppy582 snoopuppy582 requested a review from a team as a code owner May 15, 2026 23:38
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 15, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: snoopuppy582 / name: snoopuppy582 (72a9d88)

@maxnbk
Copy link
Copy Markdown
Contributor

maxnbk commented May 18, 2026

@snoopuppy582 was this issue tackled as part of devdays, or independently? Thank you.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.64%. Comparing base (d415b96) to head (72a9d88).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@snoopuppy582
Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 probing LASTEXITCODE, avoiding $? being overwritten by Test-Path.
  • Ensure a failing PowerShell command that doesn’t set LASTEXITCODE results in process exit code 1.
  • Add a Windows-only regression test covering missing-command failures for both powershell and pwsh.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug on catching exitcode for powershell commands

3 participants