Skip to content

fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments#318

Draft
margaretjgu wants to merge 1 commit into
mainfrom
fix/stdin-eagain-crash
Draft

fix(factory): handle EAGAIN/EBADF from stdin in non-blocking environments#318
margaretjgu wants to merge 1 commit into
mainfrom
fix/stdin-eagain-crash

Conversation

@margaretjgu
Copy link
Copy Markdown
Member

Summary

Fixes #311.

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, which produced an unhandled exception with a raw Node.js stack trace on any command with an input schema (the entire es namespace).

Changes

  • src/factory.ts: wrap the stdinReader() call site with a try-catch that converts EAGAIN / EBADF to 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 -- new
  • treats EBADF from stdin as no input -- new
  • re-throws unexpected stdin errors (not EAGAIN/EBADF) -- new
  • All 266 existing factory tests still pass

…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
@github-actions
Copy link
Copy Markdown

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 8.03s
✅ REPOSITORY gitleaks yes no no 53.67s
✅ REPOSITORY git_diff yes no no 0.66s
✅ REPOSITORY secretlint yes no no 29.19s
✅ REPOSITORY trivy yes no no 17.38s
✅ TYPESCRIPT eslint 2 0 0 5.94s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@margaretjgu margaretjgu marked this pull request as draft May 14, 2026 00:31
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.

bug(factory): EAGAIN crash when stdin is non-blocking but empty

1 participant