Skip to content

fix(install): capture uv stdout+stderr via Start-Process so install failures are diagnosable#156

Merged
jrob5756 merged 1 commit intomainfrom
fix/install-ps1-output-capture
May 6, 2026
Merged

fix(install): capture uv stdout+stderr via Start-Process so install failures are diagnosable#156
jrob5756 merged 1 commit intomainfrom
fix/install-ps1-output-capture

Conversation

@jrob5756
Copy link
Copy Markdown
Collaborator

@jrob5756 jrob5756 commented May 6, 2026

Problem

Reported by a user hitting an install failure on Windows: `install.ps1` reports

```
Install failed after 3 attempts.
── uv tool install output ──
(no output captured)
```

… leaving the user with no way to diagnose the failure.

Root cause

`install.ps1` sets `$ErrorActionPreference = 'Stop'` at the top, then runs:

```powershell
$output = $null
try {
$output = & uv tool install ... 2>&1
} catch {
# PowerShell treats native stderr as errors when ErrorActionPreference=Stop
}
```

When uv writes to stderr, PowerShell with `Stop` treats the stderr items as terminating errors and throws before the assignment completes, so `$output` stays `$null`. The catch swallows the actual error message. The exit-code check then fails and we display "(no output captured)".

Fix

Use `Start-Process -RedirectStandardOutput -RedirectStandardError` to temp files and read them back:

```powershell
$proc = Start-Process -FilePath 'uv' `
-ArgumentList @('tool', 'install', '--force', $installUrl, '-c', $constraintsFile) `
-NoNewWindow -Wait -PassThru `
-RedirectStandardOutput $stdoutFile `
-RedirectStandardError $stderrFile

$lastOutput = (@(Get-Content $stdoutFile -Raw, Get-Content $stderrFile -Raw) | Where-Object { $_ } | Out-String).Trim()
$lastExitCode = $proc.ExitCode
```

This bypasses PowerShell's native-error handling entirely. Output is captured every time.

Additional improvements:

  • Failure header now includes the exit code: `── uv tool install output (exit code 1) ──`
  • Multi-line output is split on `\r?\n` so each line is rendered with the leading indent
  • Fallback hint when output is genuinely empty: tells the user the exact `uv tool install` command to run manually

Verification

  • Hand-tested logic against the previous failure pattern (the user above will see uv's actual error after this lands)
  • No syntax errors (`pwsh -NoProfile -Command "& {$ErrorActionPreference='Stop'; $null = (Get-Command -Syntax install.ps1)}"` clean — but PS scripts have no formal lint in this repo)
  • This change is in install.ps1 only; no Python tests affected

…are diagnosable

The previous '& uv ... 2>&1' inside a try/catch with $ErrorActionPreference=Stop
silently swallowed all uv output: PowerShell treated native stderr items as
errors and threw before the assignment completed, leaving $output as $null.
Users hit 'Install failed after 3 attempts' followed by '(no output captured)'
with no way to diagnose.

Replace with Start-Process -RedirectStandardOutput/-RedirectStandardError to
temp files, then read both back. This works regardless of ErrorActionPreference
and gives users the actual uv error every time. Also include the exit code
in the failure header and a fallback hint pointing at the bare uv command
they can run manually if even Start-Process produces nothing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jrob5756 jrob5756 merged commit 51b7892 into main May 6, 2026
6 checks passed
@jrob5756 jrob5756 deleted the fix/install-ps1-output-capture branch May 6, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant