8000 The HadErrors property of System.Management.Automation.PowerShell reports $True in unexpected scenarios · Issue #5425 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
The HadErrors property of System.Management.Automation.PowerShell reports $True in unexpected scenarios #5425
@mklement0

Description

@mklement0

Related: #4613

The .HadErrors property of [System.Management.Automation.PowerShell] currently invariably - and unexpectedly - reflects $True in the following situations:

  • an external utility reports a nonzero exit code - even overriding $LASTEXITCODE later doesn't help that.

  • something writes to PowerShell's error stream, notably including stderr output from an external utility.

Generally, having a separate property that reflects $LASTEXITCODE would be helpful - see #5426

Examples

# Yields $True - triggered by nonzero exit code 
$ps = [PowerShell]::Create().AddScript({ whoami -nosuch }); $ps.Invoke(); $ps.HadErrors

# Unexpectedly also yields $True - despite attempt to set the exit code to 0.
$ps = [PowerShell]::Create().AddScript({ whoami -nosuch; $LASTEXITCODE = 0 }); $ps.Invoke(); $ps.HadErrors

# Unexpectedly also yields $True - triggered by native stderr output.
$ps = [PowerShell]::Create().AddScript({ bash -c 'echo err >&2'  }); $ps.Invoke(); $ps.HadErrors

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Documentation Needed in this repoDocumentation is needed in this repoIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0