Skip to content

fix(exec): report signal-terminated commands as failures - #1285

Open
FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-exec-signal-status-oct13
Open

FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-exec-signal-status-oct13

Conversation

@FanWu-ai

Copy link
Copy Markdown

Fixes #1034.

Problem

When a signal terminates a command, Node reports err.code === null. The synchronous helper assigned that value to process.exitCode and reported success, while the asynchronous callback received null. This can allow a script to continue after a failed command, including when synchronous fatal behavior was requested.

Changes

  • Use the existing generic failure status 1 for signal-terminated commands in both execution modes.
  • Preserve captured stdout/stderr and native ChildProcess.signalCode/exitCode information.
  • Convert only the synchronous error diagnostic to text, retaining returned stdout/stderr Buffers when encoding: 'buffer' is requested. This also handles the existing Buffer/nonzero-exit diagnostic failure in the same error path.

Verification

Node.js 24.19.0 on Linux x86_64:

  • Pristine full suite: 640 passed, 6 pre-existing explicit skips.
  • Added 12 tests. Eleven fail against unchanged production code; the ordinary numeric-exit control passes.
  • Final focused exec suite: 39 passed.
  • Final npm test, including posttest ESLint: 652 passed, 6 pre-existing explicit skips.
  • Final npm run test-with-coverage: 652 passed, 6 skipped; 95.63% statement coverage and 96.45% line coverage.
  • npm run check-node-support, npm run gendocs, and git diff --check passed. Regenerating documentation leaves README unchanged.
  • Independent supplemental review passed 30 cases covering HUP/INT/TERM/KILL, synchronous/asynchronous execution, fatal behavior, Buffer output, and exit codes 0/1/7/12/127/255.

The six reported skips are existing test/cmd.js cases: five asynchronous-command cases and the missing-execPath case. The new signal-specific tests run on POSIX and explicitly skip on Windows. Other operating systems and Node versions have not been run locally.

AI assistance: OpenAI Codex assisted the investigation, implementation, testing, and independent review.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 12, 2026 21:34
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.

Exit code of sh.exec() is not always correct.

1 participant