fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments#318
Draft
margaretjgu wants to merge 1 commit into
Draft
fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments#318margaretjgu wants to merge 1 commit into
margaretjgu wants to merge 1 commit into
Conversation
…ents In IDE terminals (Cursor, VS Code integrated terminal) and some CI environments, process.stdin.isTTY is falsy even when no data is piped. Attempting a synchronous readFileSync(0) in those conditions fails with EAGAIN (non-blocking fd, no data ready) or EBADF, producing an unhandled exception with a raw Node.js stack trace. Catch EAGAIN and EBADF at the stdinReader call site and treat them as empty input, consistent with the existing empty-string path. All other errors are re-thrown unchanged. Fixes #311
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
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
Fixes #311.
In IDE terminals (Cursor, VS Code integrated terminal) and some CI environments,
process.stdin.isTTYis falsy even when no data is piped. Attempting a synchronousreadFileSync(0)in those conditions fails withEAGAIN(non-blocking fd, no data ready) orEBADF, which produced an unhandled exception with a raw Node.js stack trace on any command with aninputschema (the entireesnamespace).Changes
src/factory.ts: wrap thestdinReader()call site with a try-catch that convertsEAGAIN/EBADFto empty string, consistent with the existing empty-string path. All other errors are re-thrown unchanged.test/factory.test.ts: three new tests covering EAGAIN, EBADF, and re-throw of unexpected errors.Test plan
treats EAGAIN from stdin as no input-- newtreats EBADF from stdin as no input-- newre-throws unexpected stdin errors (not EAGAIN/EBADF)-- new