Skip to content

fix: silence stderr on best-effort package-manager probes#491

Open
huangguang1999 wants to merge 1 commit into
sirmalloc:mainfrom
huangguang1999:fix/probe-stderr-leak
Open

fix: silence stderr on best-effort package-manager probes#491
huangguang1999 wants to merge 1 commit into
sirmalloc:mainfrom
huangguang1999:fix/probe-stderr-leak

Conversation

@huangguang1999

Copy link
Copy Markdown
Contributor

Problem

On a machine where bun is on PATH but its global directory was never initialized (the user never ran bun add -g — e.g. they installed ccstatusline via npm install -g), launching the config TUI prints bun's error straight into the terminal:

error: No package.json was found for directory "C:\Users\alice\.bun\install\global"

(Reported downstream in a localized fork: huangguang1999/ccstatusline-zh#39, with screenshots.)

Root cause

Installation inspection probes bun pm bin -g (plus where/which, npm prefix -g, npm root -g) through execFileSync without an stdio option. Node's default inherits the child's stderr into the parent terminal, so even though the thrown error is caught (catch { return null; }), the stderr text has already leaked. On Windows, where similarly writes INFO: Could not find files... to stderr when nothing matches.

Other probes in the codebase already suppress stderr (e.g. usage-fetch.ts uses stdio: ['pipe', 'pipe', 'ignore']) — these calls just missed the pattern.

Fix

Add stdio: ['ignore', 'pipe', 'ignore'] to the best-effort probe calls (stdout stays piped for the return value). No behavior change: these functions already treat any failure as "not found".

Tests

  • New test asserting every probe execFileSync call carries stderr suppression (regression guard).
  • New test simulating the exact bun error and asserting graceful "not found" degradation.
  • bun run lint clean, bun test 1630 tests green.

🤖 Generated with Claude Code

When bun is on PATH but its global directory was never initialized
(no `bun add -g` ever run), launching the config TUI prints
`error: No package.json was found for directory "~/.bun/install/global"`
into the terminal. The TUI probes `bun pm bin -g` (and `where`/`which`,
`npm prefix -g`, `npm root -g`) via execFileSync without an stdio
option, so the child's stderr is inherited by the parent terminal even
though the thrown error itself is caught and treated as "not found".

Add stdio: ['ignore', 'pipe', 'ignore'] to these best-effort probes
(stdout stays piped for the return value), matching the pattern already
used elsewhere in the codebase. Adds regression tests asserting every
probe call suppresses stderr and that a throwing bun probe degrades
gracefully.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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