-
Notifications
You must be signed in to change notification settings - Fork 357
PowerShell: Fix assumption that $LASTEXITCODE is always defined
#1962
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: Fix assumption that $LASTEXITCODE is always defined
#1962
Conversation
5570323 to
e9a8f0c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1962 +/- ##
==========================================
+ Coverage 59.28% 59.30% +0.01%
==========================================
Files 126 126
Lines 17218 17219 +1
Branches 3017 3017
==========================================
+ Hits 10208 10211 +3
+ Misses 6325 6323 -2
Partials 685 685 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @nrusch, thanks for creating this PR. Unfortunately, it looks like your change is breaking the tests for pwsh on macOS. Can you take a look at that please? Also, do you think there would be a way to test this specific behavior? I would guess that a test would probably look something like https://github.com/AcademySoftwareFoundation/rez/blob/main/src/rez/tests/test_shells.py#L594-L608. |
Signed-off-by: Nathan Rusch <nathan.rusch@scanlinevfx.com>
13c86ee to
116a993
Compare
|
Hey @JeanChristopheMorinPerso, I've been poking around with this, and I think there may actually be a "bug" in the Specifically, its So, what is the Even if I install However, this does not actually end up failing the test. |
4ceb7a3 to
d96dd3b
Compare
|
Interesting finding! I'm kind of surprised that it's failing. I went through those tests very carefully, one by one. But maybe I forgot one and missed something... From the look of it, |
d96dd3b to
d6c024c
Compare
Signed-off-by: Nathan Rusch <nathan.rusch@scanlinevfx.com>
d6c024c to
1d30482
Compare
|
OK, I've got the baseline tests working now after an update to the I will look at adding a new test for the behavior change... I'll just have to think about what shape it might take. |
|
Thanks! I can give it a try tomorrow. But in general, I trust our tests (only because I spent days last year making sure they were testing what they were supposed to). As for the new test, I have an idea, but it's probably a "bad" one... Basically, I'm wondering if creating a "gui" executable from https://github.com/AcademySoftwareFoundation/rez/blob/main/src%2Frez%2Fbind%2Fhello_world.py#L52 would allow to replicate the scenario you want to test. This could be done using |
|
That's more or less what I had in mind, and I've been able to confirm that a basic auto-generated "GUI script" entrypoint can be used to reproduce the error on Windows before this patch is applied. I guess the one question is just whether a GUI entrypoint will run as expected in CI, but we'll find out. |
|
In the course of creating a reproducible test failure to A/B my fix against, I realized that one of the critical ingredients for hitting this error is to be running PowerShell in "strict" mode. From the PowerShell documentation:
We run PowerShell with I have manufactured a test case using a Windows GUI entrypoint and confirmed that I can reproduce the error I originally reported here prior to my patch using a test with |
Signed-off-by: Nathan Rusch <nathan.rusch@scanlinevfx.com>
Signed-off-by: Nathan Rusch <nathan.rusch@scanlinevfx.com>
dd25fdc to
afb72bb
Compare
|
OK, I've added a (perhaps somewhat contrived) test for the GUI application return behavior. Let me know what you think. |
JeanChristopheMorinPerso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the hard work on this! I left a small comment that should be easy to address. Apart from that, I'm ready to approve this.
Signed-off-by: Nathan Rusch <nathan.rusch@scanlinevfx.com>
6cdb847
into
AcademySoftwareFoundation:main
#1778 added support for surfacing the exit code from aliased commands to the rez shell. However, it assumes
$LASTEXITCODEwill always be defined after any command is run, which is not safe.On Windows, GUI applications will detach from their parent process at startup unless explicitly written to (re)attach. In PowerShell, this manifests as the command execution returning immediately, and
$LASTEXITCODEbeing left unmodified, which means it may not be defined all depending on what has previously been run in the shell.When running PowerShell with
Set-StrictModeenabled, attempting to access an undefined variable is treated as an error, rather than returning0or$null.Thus, launching a GUI application using a
rez-envcall (e.g.rez-env some_package -- some_app.exe) in a "strict" PowerShell session leads to an error like the following:This MR fixes this particular error by ensuring
$LASTEXITCODEis actually defined before trying to read it.