Skip to content

fix: report real command exit codes from the PowerShell prompt wrapper - #39

Merged
HelloThisWorld merged 1 commit into
mainfrom
fix/prompt-exit-code-capture
Aug 4, 2026
Merged

fix: report real command exit codes from the PowerShell prompt wrapper#39
HelloThisWorld merged 1 commit into
mainfrom
fix/prompt-exit-code-capture

Conversation

@HelloThisWorld

Copy link
Copy Markdown
Owner

Problem

Every Command Timeline entry in 1.3.0-beta1 shows Succeeded, including commands that clearly failed (node src\broken.js, missing-path cmdlet errors). Failure marks can never appear.

Root cause

Enable-WinTermShellIntegration installs a prompt wrapper whose first statement is Get-Module -Name 'winTerm.Shell'. That statement succeeds and resets $? before Invoke-WinTermPrompt reads it, so Get-WinTermExitCode -LastSuccess $true short-circuits to 0 on every prompt. The 133;D mark therefore always reports exit code 0 and the timeline renders every finished command as Succeeded.

Fix

  • The wrapper captures $? as its first statement and passes it into the module call: & $module { param($s) Invoke-WinTermPrompt -LastSuccess $s } $winTermLastSuccess.
  • Invoke-WinTermPrompt gains an optional -LastSuccess parameter; when omitted it still reads $? at entry, preserving direct-invocation behavior.

Tests

scripts/winterm/test-shell-integration.ps1 gains Test-PowerShellPromptExitCodes, which enables integration and drives the installed global prompt function the same way the console host does:

  • first prompt emits 133;A and no 133;D
  • successful command → 133;D;0
  • failed cmdlet (Get-Item on a missing path) → 133;D;1
  • native failure (cmd /c exit 5) → 133;D;5
  • success after a failure recovers to 133;D;0

Verified red on the unfixed module (fails with "A failed cmdlet was not reported as exit code 1.") and green with the fix. Full suite (WindowsPowerShell + PowerShell7 + CMD) passes, and the privacy gate passes.

The prompt wrapper ran Get-Module before Invoke-WinTermPrompt could read
$?, so LastSuccess was always true and Get-WinTermExitCode returned 0 for
every finished command. The Command Timeline therefore showed Succeeded
for failing cmdlets and for native commands with non-zero exit codes.

The wrapper now captures $? as its first statement and hands it to
Invoke-WinTermPrompt through a -LastSuccess parameter. Direct invocations
without the parameter keep the previous behavior of reading $? at entry.

The shell integration suite gains an installed-wrapper regression test
that drives the global prompt function exactly like the console host: the
first prompt must not emit a finished mark, a successful command must
report 133;D;0, a failed cmdlet 133;D;1, a native exit code 133;D;5, and
a later success must recover to 133;D;0.
@HelloThisWorld
HelloThisWorld merged commit a6ec9a4 into main Aug 4, 2026
5 checks passed
@HelloThisWorld
HelloThisWorld deleted the fix/prompt-exit-code-capture branch August 4, 2026 15:03
HelloThisWorld added a commit that referenced this pull request Aug 4, 2026
Second beta of the Command Timeline release. It carries the prompt
wrapper exit code fix from #39 and is otherwise identical to beta1.

- Application version 1.3.0-beta2, package/file version 1.3.0.5,
  PowerShell module 1.3.0 with prerelease suffix beta2, channel beta.
- Version literals moved across the branding metadata, manifests,
  resource scripts, and the six verification scripts that pin them.
- README source version and build examples advanced to 1.3.0-beta2;
  the stable download reference stays at 1.2.0.
- CHANGELOG, current progress, and docs/releases/1.3.0-beta2.md record
  the beta1 finding and the fix.
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.

1 participant