Skip to content

PS 5.1 turns native stderr into NativeCommandError

streams · case

5.1misleading-errorscriptcithird-partyrepro: verifiedstream-wrapping
Affectspowershell 51, windows
Fails asNATIVECOMMANDERROR
Mechanismstream wrapping
Safe fixcontinue eap

A native tool that merely writes progress to stderr (git, uv, npm, curl) appears to FAIL under Windows PowerShell 5.1: red NativeCommandError text, or — with $ErrorActionPreference = 'Stop' — the whole script terminates even though the tool exited 0.

Terminal window
# Windows PowerShell 5.1, with strict error preference
$ErrorActionPreference = 'Stop'
uv python install 3.12 2>&1 # uv writes progress to stderr
# -> script terminates: uv's progress lines became ErrorRecord objects

When 5.1 redirects a native command’s stderr (2>&1, or captures in a variable), each stderr line is wrapped in an ErrorRecord and surfaced through the error stream. Combined with $ErrorActionPreference='Stop', successful commands become fatal errors. The hermes-agent installer hit this with uv and shipped a fix that relaxes EAP around the native call and verifies success separately (see ref). PowerShell 7.2+ no longer wraps native stderr this way.

  • Do not combine 2>&1 with Stop preference around native commands on 5.1.
  • Temporarily set $ErrorActionPreference='Continue' around the call, then check $LASTEXITCODE.
  • The cli-jaw installer documents this exact hazard in its 5.1-safe install path.