Skip to content

fix(convert): read stdin as a stream and guard against TTY-only invocations#184

Merged
pchuri merged 1 commit into
mainfrom
fix/convert-stdin-handling
May 12, 2026
Merged

fix(convert): read stdin as a stream and guard against TTY-only invocations#184
pchuri merged 1 commit into
mainfrom
fix/convert-stdin-handling

Conversation

@pchuri
Copy link
Copy Markdown
Owner

@pchuri pchuri commented May 12, 2026

Summary

  • The convert command read stdin via fs.readFileSync(process.stdin.fd, 'utf-8'). That's a known-fragile pattern: it can hit EAGAIN on some platforms, and when the user invokes the command interactively (no pipe, no --input-file) the process just hangs forever waiting on the TTY.
  • Switch to an async stream consumer for stdin, and fail fast with a clear error when process.stdin.isTTY is true.

Test plan

  • npm test — 680/680 pass
  • npm run lint — clean
  • Added regression tests covering the piped paths: # Piped\n... reads via stdin, empty pipe (input: '') returns empty output without hanging
  • Manual: echo '# Hi' | confluence convert --input-format markdown --output-format storage works; ... </dev/null returns empty

Not in automated tests

The TTY guard itself isn't covered by Jest — execFileSync always attaches pipes to the child, so process.stdin.isTTY is always false in the test harness. Verifying the TTY branch would require a pty wrapper (node-pty or similar), which felt like overkill for a 4-line if (isTTY) { console.error; exit(1) }. Reviewed by inspection instead.

…ations

`fs.readFileSync(process.stdin.fd, 'utf-8')` is fragile across platforms
and silently hangs when the command is run interactively without piped
input. Replace it with an async stream consumer and surface a clear
error when stdin is a TTY.
@pchuri pchuri self-assigned this May 12, 2026
@pchuri pchuri merged commit fda2860 into main May 12, 2026
6 checks passed
@pchuri pchuri deleted the fix/convert-stdin-handling branch May 12, 2026 12:50
github-actions Bot pushed a commit that referenced this pull request May 12, 2026
## [2.6.3](v2.6.2...v2.6.3) (2026-05-12)

### Bug Fixes

* **convert:** read stdin as a stream and guard against TTY-only invocations ([#184](#184)) ([fda2860](fda2860))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.6.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant