Skip to content

fix: guard optional onExit cleanup handler - #237

Open
pupuking723 wants to merge 1 commit into
npm:mainfrom
pupuking723:fix/onexit-cleanup-handler
Open

fix: guard optional onExit cleanup handler#237
pupuking723 wants to merge 1 commit into
npm:mainfrom
pupuking723:fix/onexit-cleanup-handler

Conversation

@pupuking723

Copy link
Copy Markdown

Fixes #84.

signal-exit can return undefined from onExit() in some versions/environments. write-file-atomic currently assumes the return value is always a remover function, so the async and sync paths can throw while leaving the finally cleanup section even when the write itself succeeded.

This adds a no-op fallback for the optional remover and covers both async and sync writes with a regression test that mocks onExit() to return undefined.

Verification:

  • npx tap --no-coverage test/basic.js
  • npm run eslint -- lib/index.js test/basic.js
  • git diff --check
  • npm test passes tests, coverage, and eslint locally, then fails only in template-oss-check because the generated repository template wants unrelated .github branch/template updates. I did not include those unrelated tooling changes in this bugfix PR.

@pupuking723
pupuking723 requested a review from a team as a code owner June 13, 2026 06:15
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] Does not handle undefined return value from signal-exit's onExit() function

1 participant