fix: exit codes were 127 on any receipt path that touched I/O - #5
Merged
Merged
Conversation
The entry point called process.exit(code), which tears the process down immediately. On Windows, if a libuv async handle is mid-close when that happens — which it is on any path that did fs or network I/O — Node aborts: Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76 The verdict is printed before that, so the output looked correct while the shell saw 127 instead of the documented code. Every exit code in the README was wrong on those paths: valid local file 127 (documented 0) tampered 127 (documented 1) malformed 127 (documented 3) CI consumers are the one audience that reads the exit code rather than the text, so this broke exactly the users the codes exist for. Assigning process.exitCode instead lets Node close its handles and exit normally. All five paths now return their documented code with no abort. Nothing caught this because the existing CLI tests exercise the CERTIFICATE path with --offline, which never opens a socket and so never hits the race. src/exit-codes.test.ts covers the receipt path, including a local-file read that still fetches the public key — the exact combination that aborted — and asserts both the code and the absence of an abort. 65 tests pass, up from 59. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
The bug
The entry point called
process.exit(code), which tears the process down immediately. On Windows, if a libuv async handle is mid-close when that happens — which it is on any path that did fs or network I/O — Node aborts:The verdict is printed before that, so output looked correct while the shell saw 127 instead of the documented code:
--versionCI consumers are the one audience that reads the exit code rather than the text, so this broke precisely the users the codes exist for. The README publishes them as a contract.
The fix
Assign
process.exitCodeand let the event loop drain, instead of forcing exit. Node then closes its handles and exits normally with the requested code. All five paths verified by hand:Why nothing caught it
The existing CLI tests exercise the certificate path with
--offline, which never opens a socket and so never hits the race.src/exit-codes.test.tscovers the receipt path — including a local-file read that still fetches the public key, the exact combination that aborted — and asserts both the code and the absence of an abort, so a regression cannot hide behind correct-looking stdout.65 tests pass, up from 59.
Relationship to the npx 127
This is a different 127 from the
npx github:failure fixed in #4. That one was bin resolution — nothing ran. This one runs, prints the right answer, and then dies. They share an exit code and nothing else; both needed fixing.🤖 Generated with Claude Code