Launcher: propagate the native process exit code #15

Open
Yoshi-233 wants to merge 1 commit from upstream-pr/15 into main
Yoshi-233 commented 2026-11-25 03:06:38 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Yoshi-233 on 2026-11-25T02:56:58Z.


Fixes #3. A batch job invoking powershell -File scripts/play.ps1 currently sees success even when the child reports an error. Save the native exit code immediately after the output pipeline and return it after printing the existing status line. Thanks to @yualk for the Windows reproduction and suggested fix.

I exercised the unchanged and patched scripts in separate PowerShell 7.7.0 processes on Ubuntu 24.04.5 x86-64, using a small native child supplied via -Exe:

Child exit Caller before Caller after
0 0 0
1 0 1
7 0 7
42 0 42

For each run, the script printed the child status, the log contained both output streams, and the child received the path containing spaces as one argument. I also ran the Linux CLI from #1: its normal “running titles requires Windows” error returned 1 directly, 0 via the original wrapper, and 1 via the patched wrapper. The same diagnostic reached the log.

The Windows PowerShell 5.1 reproduction and its result are in #3. My runs used Linux and required no game files.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6596153854 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/15). Originally posted by [Yoshi-233](https://github.com/Yoshi-233) on 2026-11-25T02:56:58Z. --- Fixes #3. A batch job invoking `powershell -File scripts/play.ps1` currently sees success even when the child reports an error. Save the native exit code immediately after the output pipeline and return it after printing the existing status line. Thanks to @yualk for the Windows reproduction and suggested fix. I exercised the unchanged and patched scripts in separate PowerShell 7.7.0 processes on Ubuntu 24.04.5 x86-64, using a small native child supplied via `-Exe`: | Child exit | Caller before | Caller after | | ---: | ---: | ---: | | 0 | 0 | 0 | | 1 | 0 | 1 | | 7 | 0 | 7 | | 42 | 0 | 42 | For each run, the script printed the child status, the log contained both output streams, and the child received the path containing spaces as one argument. I also ran the Linux CLI from #1: its normal “running titles requires Windows” error returned 1 directly, 0 via the original wrapper, and 1 via the patched wrapper. The same diagnostic reached the log. The Windows PowerShell 5.1 reproduction and its result are in #3. My runs used Linux and required no game files.
kaayzouee commented 2026-11-25 04:11:31 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by kaayzouee on 2026-11-25T03:24:39Z.


Code review — Approved

Reviewed commit afe450a.
Correctness and simplicity

Capturing $LASTEXITCODE immediately after the native process pipeline, printing the captured value, and returning it with exit is correct.

The intervening Out-File cmdlet does not itself overwrite the native process exit code.

The implementation is minimal, readable, and appropriately scoped. Retaining $childExitCode ensures the displayed and returned values remain consistent. No further simplification is necessary.

Nonblocking recommendations

A failure to start the executable is different from a child process returning a nonzero exit code. In the former case, $LASTEXITCODE may be unset or stale.

PR #17 addresses part of this separately. After both changes are merged, consider testing nonexistent executables and executables that exist but cannot be started.

The reported Linux tests covering exit codes 0, 1, 7, and 42 provide useful regression evidence. Retaining these as automated tests and repeating them on Windows PowerShell 5.1 would improve coverage.

Verdict

Approve as-is. No blocking regression identified. The separate executable-discovery and startup-failure concerns should not hold up this change.

Static review only. I inspected the candidate, target branch, related PR #17, and PowerShell documentation. PowerShell was unavailable in my review environment, so the reported tests were not independently executed.

⸻

This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7151888015 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/15#issuecomment-7151888015). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T03:24:39Z. --- Code review — Approved Reviewed commit afe450a. Correctness and simplicity Capturing $LASTEXITCODE immediately after the native process pipeline, printing the captured value, and returning it with exit is correct. The intervening Out-File cmdlet does not itself overwrite the native process exit code. The implementation is minimal, readable, and appropriately scoped. Retaining $childExitCode ensures the displayed and returned values remain consistent. No further simplification is necessary. Nonblocking recommendations A failure to start the executable is different from a child process returning a nonzero exit code. In the former case, $LASTEXITCODE may be unset or stale. PR #17 addresses part of this separately. After both changes are merged, consider testing nonexistent executables and executables that exist but cannot be started. The reported Linux tests covering exit codes 0, 1, 7, and 42 provide useful regression evidence. Retaining these as automated tests and repeating them on Windows PowerShell 5.1 would improve coverage. Verdict Approve as-is. No blocking regression identified. The separate executable-discovery and startup-failure concerns should not hold up this change. Static review only. I inspected the candidate, target branch, related PR #17, and PowerShell documentation. PowerShell was unavailable in my review environment, so the reported tests were not independently executed. ⸻ This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.
Yoshi-233 commented 2026-11-25 12:07:14 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Yoshi-233 on 2026-11-25T11:59:52Z.


I verified afe450a on native Windows PowerShell 5.1.26100.9711 using powershell.exe -File and a small executable passed to -Exe.

Child exit code Caller on 90b529f Caller on afe450a
0 0 0
1 0 1
7 0 7
42 0 42

In all four patched runs, the game path containing spaces and brackets arrived as a single argument, and both stdout and stderr reached ztrx.log. The combined test with #53 also propagated the child’s exit code after a successful directory retry.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7161781589 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/15#issuecomment-7161781589). Originally posted by [Yoshi-233](https://github.com/Yoshi-233) on 2026-11-25T11:59:52Z. --- I verified `afe450a` on native Windows PowerShell 5.1.26100.9711 using `powershell.exe -File` and a small executable passed to `-Exe`. | Child exit code | Caller on `90b529f` | Caller on `afe450a` | | ---: | ---: | ---: | | 0 | 0 | 0 | | 1 | 0 | 1 | | 7 | 0 | 7 | | 42 | 0 | 42 | In all four patched runs, the game path containing spaces and brackets arrived as a single argument, and both stdout and stderr reached `ztrx.log`. The combined test with #53 also propagated the child’s exit code after a successful directory retry.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/15:upstream-pr/15'
git switch 'upstream-pr/15'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/15'
git switch 'upstream-pr/15'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/15'
git switch 'upstream-pr/15'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/15'
git switch 'main'
git merge --squash 'upstream-pr/15'
git switch 'main'
git merge --ff-only 'upstream-pr/15'
git switch 'main'
git merge 'upstream-pr/15'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Zettrox/ztrx!15
No description provided.