PowerShell: NativeCommandExitException should display "negative" exit codes in hex, not decimal

Prerequisites

Steps to reproduce

When a native command exits with a “negative” (high-order bit set) exit code, PowerShell 7.4.0-preview.4 displays something like:

NativeCommandExitException: Program "winget.exe" ended with non-zero exit code: -1978335212.

This negative value cannot (really) be made sense of unless you convert it to hex (0x8a150014 in that case).

Expected behavior

NativeCommandExitException: Program "winget.exe" ended with non-zero exit code: 0x8a150014.

Actual behavior

NativeCommandExitException: Program "winget.exe" ended with non-zero exit code: -1978335212.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.4
PSEdition                      Core
GitCommitId                    7.4.0-preview.4
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 28 (11 by maintainers)

Most upvoted comments

The Engine WG reviewed this issue and agrees with @Luiz-Monad. The message can easily be updated to display the int ExitCode in both decimal and hexadecimal.

There’s no true correct answer for this situation, really.

So I propose:

NativeCommandExitException: Program "winget.exe" ended with non-zero exit code: -1978335212 (0x8a150014).

Why not both ! image

again, the value is AND-ed with 0xFF:

Then why (bash):

$ bash -c "exit 1000000"
$ echo -e $?
64

because 1000000 is 0x000F4240 and 0x40 is 64