Skip to content

Failed commands should write an error #9140

@chriskuech

Description

@chriskuech

Background

Error handling in PowerShell is extremely messy, by far the primary complaint I have heard about the language, and has actually been cited as a reason to not use PowerShell. The two major complaints I've heard about error handling are:

Current behavior

When running a binary command in PowerShell (ex: git) and the binary errors, the command does not always output an error (neither terminating nor non-terminating). PowerShell clearly detects that the command fails and correctly populates $?, but does not integrate with normal error handling mechanisms. The result is this cumbersome syntax:

git checkout -b master
if (-not $?) {
    throw "Command failed"
}

Summary of the new feature/enhancement

If a command sets $? to $false, then the command should write an error to the error stream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions