fix(telemetry): handle EPIPE errors from piped stdout gracefully#250
Merged
fix(telemetry): handle EPIPE errors from piped stdout gracefully#250
Conversation
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
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Build
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ Patch coverage is 82.35%. Project has 4129 uncovered lines. Files with missing lines (71)
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When CLI output is piped through commands like
headorjq, 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: Registererrorevent listeners onprocess.stdout/process.stderrthat exit cleanly (code 0) on EPIPE, matching standard CLI tool behavior (gh,npm, etc.)src/lib/telemetry.ts: AddisEpipeError()helper and wire intobeforeSendto drop any EPIPE events from Sentry telemetry as a safety netWhy this approach
WriteWrap.onWriteComplete/ Bun'swriteFast) — they bypass alltry/catchblocks and surface as uncaught exceptionserrorevent handlers catch all 167+stdout.write()call sites in one place — no need to wrap each individuallybeforeSendfilter is belt-and-suspenders in case there's a race between the stream handler and the SDK's uncaught exception capture