Repository navigation
fix: record the real exit code from the PowerShell prompt hook - #324
Merged
Merged
Conversation
The prompt function read `$LASTEXITCODE` into a variable before reading `$?`. `$?` describes only the previous statement, so by then it described that assignment and was always true: every failing command was recorded as exit_code 0. `cmd /c exit 3` and a missing path both came back 0. Found by running a packaged Windows build; no test ran the hook. The new test drives the hook in a real interactive PowerShell (pwsh and Windows PowerShell 5.1, whichever exist), reads the events it spools, and checks a failing native command, a failing cmdlet, and that a failure is not carried into the next successful command. All three fail on the old order. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
hooks/shell-hook.ps1: thepromptfunction read$LASTEXITCODEinto a variable before reading$?.$?describes only the previous statement, so by then it described that assignment and was always$true. Every failing PowerShell command was recorded asexit_code: 0.The fix is to read
$?first (the two lines swap, plus a comment saying why).How it was found
Not by a test. I ran a packaged Windows build against an isolated profile and drove the hook in a real PowerShell:
cmd /c exit 3was recorded withexit_code: 0. Confirmed in isolation on both Windows PowerShell 5.1 and pwsh 7 — the shipped order givessuccess=True, the swapped order givessuccess=False.Test
test/powershell-hook-exit-code.test.tsstarts an interactive PowerShell (pwsh and Windows PowerShell, whichever exist; nothing is declared if neither does), dot-sources the hook with a tempUSERPROFILE, feeds commands on stdin, and reads the events the hook spools to~/.redlog/pending(no RedLog is running, so there is noapi-port). It checks:All three fail on the old order (verified by running them before the fix), and all six (3 × 2 shells) pass after.
Checks
typecheck, verify:specs, verify:architecture, verify:i18n,
npm test(343 files / 3503 tests passed, 33 skipped) — all green locally on Windows.Not covered
pwshis not on the runner the suite declares nothing rather than failing, so on CI it may be a no-op; the Windows run above is what exercised it.Refs #226
🤖 Generated with Claude Code