Skip to content

Fix transcript logging for exit flow control#27526

Open
KirtiRamchandani wants to merge 1 commit into
PowerShell:masterfrom
KirtiRamchandani:fix/transcript-exit-flowcontrol
Open

Fix transcript logging for exit flow control#27526
KirtiRamchandani wants to merge 1 commit into
PowerShell:masterfrom
KirtiRamchandani:fix/transcript-exit-flowcontrol

Conversation

@KirtiRamchandani
Copy link
Copy Markdown

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 contained PS>TerminatingError(): "System error."
  • Start-PSBuild -UseNuGetOrg -SkipExperimentalFeatureGeneration
  • Start-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

Copilot AI review requested due to automatic review settings May 25, 2026 01:35
@KirtiRamchandani KirtiRamchandani requested a review from a team as a code owner May 25, 2026 01:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a regression test and a runtime change to prevent PowerShell transcription from logging terminating errors when execution ends via flow control (e.g., exit from an advanced function).

Changes:

  • Add Pester coverage for transcription behavior when an advanced function calls exit.
  • Update pipeline error logging to ignore FlowControlException during execution exception logging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/powershell/Modules/Microsoft.Powershell.Host/Start-Transcript.Tests.ps1 Adds a regression test ensuring transcripts don’t include a terminating error record when a function exits via exit.
src/System.Management.Automation/engine/pipeline.cs Skips execution-exception logging for FlowControlException to avoid emitting terminating error records for flow-control exits.

Exit-Script
"@ | Set-Content -Path $scriptFilePath

& "$PSHOME/pwsh" -NoProfile -File $scriptFilePath *> $null

$LASTEXITCODE | Should -Be 255
$exitTranscriptFilePath | Should -Exist
Get-Content -Path $exitTranscriptFilePath -Raw | Should -Not -Match 'TerminatingError\(\): "System error\."'
Comment on lines +165 to +166
if (exception is FlowControlException)
return;
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.

Using the exit statement from an advanced function logs TerminatingError(): "System error." within a transcription.

2 participants