Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

PSNativeCommandErrorActionPreference non-zero 0 exit code exception false positive #20034

Copy link
Copy link
@ThomasNieto

Description

@ThomasNieto
Issue body actions

Prerequisites

Steps to reproduce

There are quite a few programs that return non-zero success exit codes. With the PSNativeCommandErrorActionPreference experimental feature turned on this causes errors to be emitted to the console.

I propose that a variable and/or cmdlet maintain a dictionary of program successful exit codes to be checked at runtime when a program runs a non-zero exit code. The dictionary could also be expanded to include error codes. Imagine a community module(s) with a set of programs and success/error exit codes with descriptions that PowerShell could leverage to return to the user.

Register-ProgramExitCode [-Name] <string> [-ExitCode] <int> [[-Description] <string>] [[-Status] {Success | Error}] [<CommonParameters>]

A current example with brew:

PS /home/thomas> brew
Example usage:
  brew search TEXT|/REGEX/
  brew info [FORMULA|CASK...]
  brew install FORMULA|CASK...
  brew update
  brew upgrade [FORMULA|CASK...]
  brew uninstall FORMULA|CASK...
  brew list [FORMULA|CASK...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA|CASK

Contributing:
  brew create URL [--no-fetch]
  brew edit [FORMULA|CASK...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh
NativeCommandExitException: Program "brew" ended with non-zero exit code: 1.

Expected behavior

Programs that return successful non-zero exit codes; PowerShell does not write errors.

Actual behavior

Errors are written on all non-zero exit codes.

Error details

Exception             :
    Type        : System.Management.Automation.NativeCommandExitException
    Path        : /home/linuxbrew/.linuxbrew/bin/brew
    ExitCode    : 1
    ProcessId   : 1125
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Program "brew" ended with non-zero exit code: 1.
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ProgramExitedWithNonZeroCode
    Message     : Program "brew" ended with non-zero exit code: 1.
    HResult     : -2146233087
TargetObject          : /home/linuxbrew/.linuxbrew/bin/brew
CategoryInfo          : NotSpecified: (/home/linuxbrew/.linuxbrew/bin/brew:String) [], NativeCommandExitException
FullyQualifiedErrorId : ProgramExitedWithNonZeroCode

Environment data

7.4-preview4

Visuals

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Resolution-DeclinedThe proposed feature is declined.The proposed feature is declined.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.