Fix transcript logging for exit flow control by KirtiRamchandani · Pull Request #27526 · PowerShell/PowerShell
Problem
Using exit inside an advanced function can cause transcript logging to record TerminatingError(): "System error.", even though exit is a flow-control operation rather than an error that should be written to the transcript.
Root cause
PipelineProcessor.LogExecutionException logs every exception it receives as a terminating pipeline error. ExitException derives from FlowControlException, so the transcript path treats the internal control-flow exception as a user-visible terminating error.
Solution
Skip transcript terminating-error logging for FlowControlException instances, and add a regression test that launches a child PowerShell process where an advanced function exits with code 255 while transcription is active.
Tests run
- Reproduced before the fix with local
pwsh: transcript containedPS>TerminatingError(): "System error." Start-PSBuild -UseNuGetOrg -SkipExperimentalFeatureGenerationStart-PSPester -Path ./test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 -UseNuGetOrg -SkipTestToolBuild -ThrowOnFailure(23 passed)git diff --check(only existing Windows line-ending warnings)
Fixes #26625