Skip to content

fix(telemetry): handle EPIPE errors from piped stdout gracefully#250

Merged
BYK merged 1 commit intomainfrom
fix/epipe-broken-pipe
Feb 16, 2026
Merged

fix(telemetry): handle EPIPE errors from piped stdout gracefully#250
BYK merged 1 commit intomainfrom
fix/epipe-broken-pipe

Conversation

@BYK
Copy link
Member

@BYK BYK commented Feb 16, 2026

Summary

When CLI output is piped through commands like head or jq, closing the pipe causes EPIPE (errno -32) write errors. These surfaced as 14 fatal issues (~34 events) on Sentry because there was no error handler on stdout/stderr streams.

EPIPE is standard Unix behavior — not a bug.

Changes

  • src/bin.ts: Register error event listeners on process.stdout/process.stderr that exit cleanly (code 0) on EPIPE, matching standard CLI tool behavior (gh, npm, etc.)
  • src/lib/telemetry.ts: Add isEpipeError() helper and wire into beforeSend to drop any EPIPE events from Sentry telemetry as a safety net
  • Sentry: Resolved all 14 existing EPIPE issues

Why this approach

  • EPIPE errors are async (from WriteWrap.onWriteComplete / Bun's writeFast) — they bypass all try/catch blocks and surface as uncaught exceptions
  • Global stream error event handlers catch all 167+ stdout.write() call sites in one place — no need to wrap each individually
  • The beforeSend filter is belt-and-suspenders in case there's a race between the stream handler and the SDK's uncaught exception capture

When CLI output is piped through commands like `head` or `jq`, closing
the pipe causes EPIPE (errno -32) write errors. These surfaced as fatal
uncaught exceptions in Sentry (14 issues, ~34 events) because there was
no error handler on stdout/stderr streams.

- Register error handlers on process.stdout/stderr that exit cleanly
  (code 0) on EPIPE, matching standard CLI behavior (gh, npm, etc.)
- Add isEpipeError() helper and wire it into beforeSend to drop any
  EPIPE events that still reach Sentry as a safety net
- Resolve all 14 existing EPIPE issues on Sentry
@github-actions
Copy link
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Build

  • Add hole-punch tool to reduce compressed binary size by BYK in #245
  • Add gzip-compressed binary downloads by BYK in #244

Bug Fixes 🐛

  • (polyfill) Add exited promise and stdin to Bun.spawn Node.js polyfill by BYK in #248
  • (telemetry) Handle EPIPE errors from piped stdout gracefully by BYK in #250
  • (upgrade) Remove v prefix from release URLs and work around Bun.write streaming bug by BYK in #243

Internal Changes 🔧

  • (build) Replace local hole-punch script with binpunch package by BYK in #246
  • Use @sentry/api client for requests by MathurAditya724 in #226

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

Codecov Results 📊

✅ Patch coverage is 82.35%. Project has 4129 uncovered lines.
✅ Project coverage is 68.2%. Comparing base (base) to head (head).

Files with missing lines (71)
File Patch % Lines
human.ts 58.29% ⚠️ 395 Missing
resolve-target.ts 20.26% ⚠️ 366 Missing
list.ts 14.39% ⚠️ 345 Missing
api-client.ts 59.38% ⚠️ 262 Missing
list.ts 23.47% ⚠️ 212 Missing
oauth.ts 30.68% ⚠️ 183 Missing
list.ts 21.96% ⚠️ 167 Missing
plan.ts 19.37% ⚠️ 154 Missing
resolver.ts 3.23% ⚠️ 120 Missing
help.ts 19.85% ⚠️ 109 Missing
upgrade.ts 61.37% ⚠️ 107 Missing
view.ts 36.48% ⚠️ 101 Missing
interactive-login.ts 9.17% ⚠️ 99 Missing
errors.ts 5.94% ⚠️ 95 Missing
view.ts 25.81% ⚠️ 92 Missing
view.ts 39.44% ⚠️ 86 Missing
clipboard.ts 4.49% ⚠️ 85 Missing
status.ts 24.07% ⚠️ 82 Missing
migration.ts 47.44% ⚠️ 82 Missing
list.ts 27.18% ⚠️ 75 Missing
browser.ts 4.11% ⚠️ 70 Missing
login.ts 33.33% ⚠️ 64 Missing
span-tree.ts 5.00% ⚠️ 57 Missing
explain.ts 33.33% ⚠️ 56 Missing
telemetry.ts 84.59% ⚠️ 49 Missing
api.ts 89.80% ⚠️ 47 Missing
upgrade.ts 66.91% ⚠️ 46 Missing
seer.ts 75.54% ⚠️ 45 Missing
schema.ts 89.56% ⚠️ 40 Missing
refresh.ts 40.63% ⚠️ 38 Missing
seer.ts 79.87% ⚠️ 30 Missing
preload.ts 53.23% ⚠️ 29 Missing
view.ts 87.27% ⚠️ 28 Missing
utils.ts 88.94% ⚠️ 25 Missing
view.ts 61.54% ⚠️ 25 Missing
detector.ts 90.10% ⚠️ 20 Missing
binary.ts 88.67% ⚠️ 17 Missing
list.ts 91.16% ⚠️ 16 Missing
list.ts 90.70% ⚠️ 16 Missing
code-scanner.ts 95.00% ⚠️ 16 Missing
help.ts 57.14% ⚠️ 15 Missing
sentry-client.ts 92.22% ⚠️ 13 Missing
arg-parsing.ts 90.00% ⚠️ 12 Missing
dsn-cache.ts 94.62% ⚠️ 12 Missing
logout.ts 56.00% ⚠️ 11 Missing
token.ts 52.17% ⚠️ 11 Missing
fix.ts 83.61% ⚠️ 10 Missing
qrcode.ts 33.33% ⚠️ 10 Missing
fs-utils.ts 57.14% ⚠️ 9 Missing
view.ts 94.70% ⚠️ 7 Missing
project-root.ts 97.73% ⚠️ 7 Missing
version-check.ts 91.76% ⚠️ 7 Missing
feedback.ts 84.21% ⚠️ 6 Missing
auth.ts 95.52% ⚠️ 6 Missing
shell.ts 96.23% ⚠️ 6 Missing
app.ts 93.90% ⚠️ 5 Missing
region.ts 86.49% ⚠️ 5 Missing
setup.ts 97.84% ⚠️ 4 Missing
list.ts 97.33% ⚠️ 4 Missing
index.ts 95.96% ⚠️ 4 Missing
project-aliases.ts 97.40% ⚠️ 2 Missing
project-root-cache.ts 96.92% ⚠️ 2 Missing
output.ts 89.47% ⚠️ 2 Missing
alias.ts 99.42% ⚠️ 1 Missing
completions.ts 99.37% ⚠️ 1 Missing
env-file.ts 99.19% ⚠️ 1 Missing
parser.ts 98.63% ⚠️ 1 Missing
colors.ts 98.21% ⚠️ 1 Missing
trace.ts 99.16% ⚠️ 1 Missing
helpers.ts 97.62% ⚠️ 1 Missing
helpers.ts 94.74% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    68.18%    68.20%    +0.02%
==========================================
  Files          108       108         —
  Lines        12968     12985       +17
  Branches         0         0         —
==========================================
+ Hits          8842      8856       +14
- Misses        4126      4129        +3
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK marked this pull request as ready for review February 16, 2026 21:02
@BYK BYK merged commit 2b25152 into main Feb 16, 2026
23 checks passed
@BYK BYK deleted the fix/epipe-broken-pipe branch February 16, 2026 21:07
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