Skip to content

fix: reject instead of throwing when there's an error before reading stdin - #45

Merged
43081j merged 4 commits into
tinylibs:mainfrom
danielroe:fix/stdin-epipe
Jul 27, 2026
Merged

fix: reject instead of throwing when there's an error before reading stdin#45
43081j merged 4 commits into
tinylibs:mainfrom
danielroe:fix/stdin-epipe

Conversation

@danielroe

Copy link
Copy Markdown
Contributor

encountered this issue in @nuxt/cli copying the dev server URL on a headless Linux box (our xclip was a shim that exits 1 immediately on -i, but any environment where xclip / wl-copy / xsel fails to start will do it).

(it emitted a UNCAUGHT: write EPIPE error)

this simply attaches a listener for errors to make it a bit more stable 🙏

@danielroe danielroe changed the title fix: reject instead of throwing when tool exits before reading stdin fix: reject instead of throwing when there's an error before reading stdin Jul 25, 2026
Comment thread tests/index.test.ts Outdated
Comment thread src/index.ts
@43081j 43081j self-assigned this Jul 25, 2026
florian-lefebvre and others added 2 commits July 27, 2026 12:02
This basically splits the test in two:

1. Spawn a real process which has non-zero exit
  1a. This used to be an actual on-file disk but doesn't need to be. It
can be a `node -e` process.
  1b. It no longer needs to exclude win32 since it is just regular logic
that'll run on all platforms
2. Mock a process that has a zero exit but its stdin throws
  2a. For this one, we don't actually spawn a child, we just reject via
the `on` handler

This puts the test in alignment with all existing tests (it wasn't
before, as the only test writing real files and spawning on-disk
scripts).
@43081j

43081j commented Jul 27, 2026

Copy link
Copy Markdown
Member

FYI i've rewritten the test slightly so it works like the other ones. As part of that, I also added a 2nd test.

the first test, having a non-zero exit, would always hit this:

      if (code !== 0) {
        return reject(createUnknownError(command, code, stderr));
      }

which meant we had no test covering this (from a stdin error point of view):

      writeError ? reject(writeError) : resolve();

now the first test is non-zero so rejects with the unknown error, and the second test has a zero exit code so hits the writeError branch.

@43081j
43081j merged commit 80d084a into tinylibs:main Jul 27, 2026
7 checks passed
@danielroe
danielroe deleted the fix/stdin-epipe branch July 27, 2026 15:40
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.

3 participants