Skip to content

Inconsistent Start-Transcript behavior with respect to the error and information streams #4645

Closed

Description

I'm making the following assumptions about how Start-Transcript is designed to work (can't tell from the documentation):

  • Whatever streams are neither captured nor redirected are transcribed, and preference variables with respect to which Write-* cmdlets should actually produce output are honored; another way of putting it: Whatever output displays in the console, across all streams, is also what should get transcribed.

Currently, Start-Transcript doesn't always work that way:

  • Even with *>$null applied to a script that uses Start-Transcript, which should keep all streams out of the transcript, errors (stream 2) and Write-Host output (stream 6) are still transcribed.

    • You can partially keep error output out of the transcript If you use $ErrorActionPreference = 'SilentlyContinue': outside of a transcript that would silence all errors (non-terminating, statement-terminating, script-terminating - albeit the latter two against documented behavior), but in a transcript cmdlet-triggered statement-terminating errors are unexpectedly still transcribed.

    • Errors that do get transcribed are transcribed twice by default.

    • Cmdlet-triggered statement-terminating errors are preceded by an extra line repeating the error message, with a prefix such as >>TerminatingError(<command>): <message>
      It is this line that shows in the transcript even with $ErrorActionPreference = 'SilentlyContinue' in effect.

    • Unlike outside of a transcript, with $ErrorActionPreference at its default, $Continue:

      • a cmdlet-triggered statement-terminating error acts like a script-terminating one.
      • a script-terminating error prints neither to the console nor records the error in the transcript.
      • the transcript is aborted in both cases, however.
  • Even though Write-Information output (stream 6) is by default not printed to the console $InformationAction is 'SilentlyContinue' by default), it is still transcribed. [Update: This appears to have been fixed, but I don't know where and when (the problem persists in Windows PowerShell)]

Steps to reproduce

Create script t.ps1 with the following content:

$null = Start-Transcript t.log

write-warning 'warn'
write-verbose 'verbose'

write-information 'info'
write-host 'host'

write-output 'data'

# Generate a non-terminating error
Write-Error 'error'

# Generate an expression-based statement-terminating error.
1/0

# Generate a cmdlet-based statement-terminating error.
Get-Item -NoSuchParam

$null = Stop-Transcript

Then run the following commands, one after the other:

A)

./t.ps1

B)

./t.ps1 *>$null

C)

& { $ErrorActionPreference = 'SilentlyContinue'; ./t.ps1 }

Expected behavior

Inspect output file t.log:

A)
Coloring aside, whatever printed to the console should appear in the transcript (sandwiched between a header and a footer).

B)
Except for the header and footer, the transcript should be empty (all streams were suppressed).

C)
No errors of any kind should be transcribed.

Actual behavior

A)

  • INFO: info shows in the transcript, even though it doesn't show in the console (with $InformationPreference at its default value, SilentlyContinue).
    As an aside: Non-suppressed Write-Information output in the console has no INFO: prefix , but does in the transcript (whereas Write-Warning, Write-Verbose and Write-Debug print a prefix in both scenarios).

[Update: This appears to have been fixed, but I don't know where and when (the problem persists in Windows PowerShell)]

  • All errors show twice in the transcript.
    • The first instance of the cmdlet-triggered statement-terminating error is preceded by an extra line duplicating the regular error representation:
      >> TerminatingError(Get-Item): "A parameter cannot be found that matches parameter name 'NoSuchParam'."

B)

  • host (Write-Host output) still shows in the transcript.

  • All errors still show in the transcript (now only once).

C)

While the non-terminating error and the expression-triggered error were successfully suppressed, the cmdlet-triggered terminating error still shows in the transcript, but only by the extra line:
PS>TerminatingError(Get-Item): "A parameter cannot be found that matches parameter name 'NoSuchParam'."

Environment data

PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Activity

  1. added
    Issue-Discussion
    on Aug 25, 2017
  2. nowakca commented on Oct 27, 2018

    @nowakca

    I've found that if I get a 404 from an Invoke-WebRequest inside a Try/Catch handler (which catches the error and provides no output, squelching it), I don't see anything on screen (which is as it should be), but I do see a "TerminatingError(Invoke-WebRequest)" and response content in the Transcript (which should not be)

  3. rkeithhill commented on Apr 29, 2019

    @rkeithhill
    Collaborator

    OK this is a bit evil IMO. Enabling transcription should not fundamentally change the behavior of the script. I ran into this last Friday and took me a while to figure out this transcription bug was biting me. Here's my simple repro on a Linux machine using GNU make. There are two files (put in the same dir). Here is my simplified makefile:

    # make wants tabs insteads of spaces so when copying this, replace the four spaces before 
    # the warning message with a single tab.
    foo:
        $(warning SOME WARNING TEXT)
    

    And here is my test.ps1 file - be sure to chmod +x ./test.ps1 to make it executable:

    #!/usr/bin/env pwsh
    
    $ErrorActionPreference = "Stop"
    $Transcribe = 0
    
    if ($Transcribe) { Start-Transcript test.log }
    
    try {
        make -f makefile foo
        if ($LASTEXITCODE) { throw "make failed with $LASTEXITCODE" }
    
        "should get here - we do without transcription"
    }
    catch {
        "should not get here"
        throw $_
    }
    finally {
        if ($Transcribe) { Stop-Transcript }
    }
    

    With the above settings, I can execute this script and it works as I expect it to:

    makefile:4: SOME WARNING TEXT
    make: 'foo' is up to date.
    should get here - we do without transcription
    

    Now set the $Transcribe variable to 1 and re-run the script. Just enabling transcription causes the script to crash now (the error handling behavior has fundamentally changed):

    Transcript started, output file is test.log
    make: 'foo' is up to date.
    should not get here
    Transcript stopped, output file is /home/hillr/pwsh-bug/test.log
    

    BTW this issue does not crop up on Windows - adding to its "evilness".

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. added
    Resolution-No Activity
    on Nov 16, 2023
  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  9. added
    WG-Cmdlets
    and removed on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-DiscussionResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions