Fix transcript logging for exit flow control#27526
Open
KirtiRamchandani wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
FlowControlExceptionduring 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; |
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.
Problem
Using
exitinside an advanced function can cause transcript logging to recordTerminatingError(): "System error.", even thoughexitis a flow-control operation rather than an error that should be written to the transcript.Root cause
PipelineProcessor.LogExecutionExceptionlogs every exception it receives as a terminating pipeline error.ExitExceptionderives fromFlowControlException, so the transcript path treats the internal control-flow exception as a user-visible terminating error.Solution
Skip transcript terminating-error logging for
FlowControlExceptioninstances, 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
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