Skip to content

ods.ps1: native stderr redirects terminate the script under $ErrorActionPreference='Stop' on Windows PowerShell 5.1 #3003

Description

@patil2001

What happens

installers/windows/ods.ps1 sets $ErrorActionPreference = "Stop" globally (line ~38) and in several spots redirects native stderr:

  • line ~71: $null = docker info 2>$null (Test-DockerRunning)
  • line ~1978: & docker compose @flags ps ... 2>$null
  • line ~670: $curlOutput = & $curl.Source ... 2>&1

On PS 5.1, redirecting native stderr turns each stderr line into an ErrorRecord, which becomes terminating under Stop. Repro on 5.1.26100:

$ErrorActionPreference='Stop'
$null = cmd /c "echo boom 1>&2" 2>$null   # throws RemoteException :: boom

The author clearly knows this gotcha — lines ~2633-2637 and ~3370-3373 temporarily set SilentlyContinue around native calls — but these spots were missed.

Impact

  • Docker Desktop not running → .\ods.ps1 status/start dies with a raw docker info : ... error instead of the intended friendly message + exit 1.
  • repair voice: a timing-out curl writes curl: (28)... via 2>&1 and throws before the deliberate -eq 28 tolerance check (~line 672), aborting repair.

PS 7 is unaffected, but scheduled tasks / double-click use powershell.exe 5.1.

Suggested fix

Wrap those call sites in local preference scopes (same as the existing pattern), e.g. push $ErrorActionPreference='SilentlyContinue' around the native invocation and restore afterwards, or route stderr through a temp file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions