Skip to content

docs/boot.md: the Windows PowerShell 5.1 capture survives ErrorActionPreference Stop (PROC-271) - #5330

Open
LouisRiverstone wants to merge 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:boot-ps51-capture-stop
Open

LouisRiverstone wants to merge 2 commits into
ItsNotRexed:mainfrom
LouisRiverstone:boot-ps51-capture-stop

Conversation

@LouisRiverstone

@LouisRiverstone LouisRiverstone commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PROC-271 (found by dracbat): docs/boot.md's Windows PowerShell 5.1 log capture records nothing when $ErrorActionPreference is Stop.

Why. Under Stop, 5.1 turns the first native stderr line into a terminating error. 2>&1 | Out-File -Encoding utf8 $log then stops the run there, and the log has no [d3d12-trace] line, so the report reads as a run with no D3D12 call. A profile or script can set Stop without the reader knowing.

What changed. The doc now gives the 5.1 capture as a block:

& { $ErrorActionPreference = 'Continue'
    .\runtime\build\gta6rt.exe --run $exe --game-dir $pkg --trace $trace --trace-d3d12 2>&1 } |
    ForEach-Object { $_.ToString() } |
    Out-File -LiteralPath $log -Width 4096 -Encoding utf8

(After #4424 landed, this wraps its ForEach-Object / -Width 4096 pipeline, which on its own also writes 0 lines under Stop: re-measured on 5.1.26100.9444.)

This is the same pattern scripts/first_look.ps1 uses for its dry run. The doc also explains why the block is there. What it says about the BOM and the program.exe : prefix is unchanged.

Verify. I ran this on Windows PowerShell 5.1.26100.9444 with a stand-in .cmd that prints one stdout line and three [d3d12-trace] lines to stderr:

capture Continue Stop
2>&1 | Out-File -Encoding utf8 (main) 3 lines 0 lines (it throws on the first one)
the block (this PR) 3 lines 3 lines

With Stop set in the session, I also ran the block exactly as written in the doc, on several lines. It keeps all three lines and $LASTEXITCODE (0), and it leaves the outer $ErrorActionPreference at Stop. The tests/test_docs_*.py checks pass.

Overlap. #4424 (@AGInformatique81, which reads UTF-16 logs) rewrites this paragraph as well, and as the finding notes it has the same exposure. Whichever lands second will need a small rebase.

No game files.

AI-assisted (Claude Code): I reviewed and ran the PowerShell checks above.

…Preference Stop (PROC-271)

With $ErrorActionPreference = 'Stop', 5.1 turns the first native stderr line
into a terminating error, so '2>&1 | Out-File -Encoding utf8 $log' stops the
run and the log has no [d3d12-trace] line. The capture now runs inside
'& { $ErrorActionPreference = 'Continue'; ... 2>&1 } | Out-File', as
scripts/first_look.ps1 does. Measured on Windows PowerShell 5.1.26100 with a
stand-in printing three trace lines to stderr: bare capture 3 with Continue,
0 with Stop; the block 3 with both, exit code kept, the outer preference left
as it was.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-assisted Windows PowerShell 5.1.26100.9818 verification at 9a9e787. With caller ErrorActionPreference=Stop, the documented block captured stdout and all three native stderr lines for both exits 0 and 37. The file had the expected UTF-8 BOM; the first stderr line was formatted as NativeCommandError. Caller preference remained Stop. LASTEXITCODE preserved the native status, while $? was true in both runs because Out-File succeeded. Checked with a synthetic native process, CPU only.

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis. Your run adds a non-zero exit (37), and it confirms $LASTEXITCODE keeps the native status while $? is true because Out-File succeeded. That's worth knowing for anyone who scripts around this, but the doc only promises the log, so I've left it as is.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Head 9a9e787041.

tests/test_docs_*.py (all)   -> OK
git diff --check             -> clean

Reproduced the claim on Windows PowerShell 5.1.26100.9444 with a stand-in that prints one stdout line and three [d3d12-trace] lines to stderr, session $ErrorActionPreference = 'Stop':

capture lines in log
bare 2>&1 | Out-File -Encoding utf8 1 (stdout only; no trace line)
the documented & { $ErrorActionPreference='Continue'; ... 2>&1 } | Out-File all 3 trace lines, plus the first line's error record

The block leaves the outer preference at Stop and keeps $LASTEXITCODE (0). The text matches scripts/first_look.ps1's dry-run capture, and the BOM / program.exe : sentences are unchanged. The PR already notes the overlap with #4424 on this paragraph.

Verdict: good.

@King1565

Copy link
Copy Markdown

Read 9a9e787: pass with notes

  • The scope logic holds. & { ... } runs in a child scope, so $ErrorActionPreference = 'Continue' doesn't leak out. Inside the block, 2>&1 turns the 5.1 NativeCommandError records into success-stream objects before they reach the outer Stop. $LASTEXITCODE is global, so it survives the block (kacper-serewis measured exit 37).
  • The pattern matches scripts/first_look.ps1:53-58. The program.exe : prefix is still parsed (tools/boot_trace.py:32).
  • git diff --check is clean, all ten tests/test_docs_*.py pass, and git merge-tree against docs/boot.md: set LEONIDA_SHADERS in the first-boot commands (without it every pipeline state fails) #5313 merges cleanly. There's no pwsh here, so this is a reading, not a run.

Read:

  1. tools/boot_trace.py:47-50's UTF-16 error still tells the reader to use the bare 2>&1 | Out-File -Encoding utf8. That is the form this PR shows capturing nothing under Stop, so it's worth a one-line follow-up pointing it at the block.
  2. Hypothesis, not run here: PowerShell 7.2+ no longer applies $ErrorActionPreference to native stderr, so the "PowerShell 7" route is safe from this problem. But in 7.3+, with $PSNativeCommandUseErrorActionPreference = $true plus Stop, a nonzero exit (2 for an existing --trace file, 3 under LEONIDA_UNIMPLEMENTED=stop) throws after the run. The log is complete, but a script stops before boot_trace.py. That's why first_look.ps1:56 clears it.

AI-assisted (Claude Code).


Generated by Claude Code

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Merged current main in f99e0b96. #4424 has landed, and it changed the capture to 2>&1 | ForEach-Object { $_.ToString() } | Out-File -LiteralPath $log -Width 4096 -Encoding utf8. That command has the same exposure.

Re-measured on Windows PowerShell 5.1.26100.9444 with a stand-in that prints three trace lines to stderr and exits 37:

  • main's new command: 3 lines with Continue, 0 with Stop (it throws on the first line).
  • The same command in the & { $ErrorActionPreference = 'Continue'; ... 2>&1 } block: 3 lines with either, $LASTEXITCODE 37, and the session's preference unchanged.

So the doc now wraps main's command in the block. It keeps #4424's ForEach-Object / -Width 4096, keeps its paragraph, and adds the Stop explanation after it. Thanks @King1565 and @Kam471 for the reviews.

@kapitche

Copy link
Copy Markdown
Contributor

Tested f99e0b9 merged with main 561b65a (merge was a no-op) on Linux (WSL2) with Python 3.12.16 and natively on Windows PowerShell 5.1.26100.9818: pass

Docs-only change (docs/boot.md). tests/test_docs_*.py: 11 files run, 11 passed, 0 failed.

Re-ran the claim on Windows PowerShell 5.1 with a cmd.exe stand-in that writes three [d3d12-trace] lines to stderr and exits 37, using the same 2>&1 | ForEach-Object { $_.ToString() } | Out-File ... -Encoding utf8 pipeline as the doc (nothing from the repo was run):

  • no block, preference Continue: 3 lines in the log, exit 37
  • no block, preference Stop: 0 lines in the log (the run stops on the first stderr line), exit -1
  • & { $ErrorActionPreference = 'Continue'; ... } block, Continue: 3 lines, exit 37
  • block, Stop: 3 lines, exit 37, and the session's preference is still Stop afterwards.
    That matches the new paragraph. scripts/first_look.ps1 lines 62-67 do use the same & { $ErrorActionPreference = "Continue" ... } form for the dry run, as the text says.

Negative control: the "no block, Stop" case above is the control (0 lines). No code or test change in the PR.

@larpinguser larpinguser left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary: docs/boot.md wraps the gta6rt trace capture in & { $ErrorActionPreference = 'Continue'; ... } and explains that Windows PowerShell 5.1 with Stop otherwise turns the first stderr trace line into a terminating error and drops the log. It references the same pattern in scripts/first_look.ps1.

Why merge: Capture instructions now work under strict profiles without changing session preferences.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary: docs/boot.md wraps the gta6rt trace capture in & { $ErrorActionPreference = 'Continue'; ... } and explains that Windows PowerShell 5.1 with Stop otherwise turns the first stderr trace line into a terminating error and drops the log. It references the same pattern in scripts/first_look.ps1.

Why merge: Capture instructions now work under strict profiles without changing session preferences.

Verdict: Approve

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.

6 participants