Skip to content

fix(npm): propagate CLI exit code from npm wrapper (related to #214) - #268

Open
stantheman0128 wants to merge 1 commit into
zeabur:mainfrom
stantheman0128:fix/214-npm-spawn-args
Open

fix(npm): propagate CLI exit code from npm wrapper (related to #214)#268
stantheman0128 wants to merge 1 commit into
zeabur:mainfrom
stantheman0128:fix/214-npm-spawn-args

Conversation

@stantheman0128

@stantheman0128 stantheman0128 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Related to #214. The quoting half of that issue was already fixed in merged #215 (execFileSync with argv array). This PR addresses the residual exit-code propagation when the npm wrapper shells out to the platform binary.

execFileSync throws on non-zero CLI exit, so npx zeabur service exec (and similar) printed a Node stack trace and always exited 1, discarding deliberate exit codes from commands like internal/cmd/service/exec/exec.go and internal/cmd/server/exec/exec.go.

Switch to spawnSync + process.exitCode so the wrapper forwards the binary's status (including signal-terminated runs).

AI disclosure

AI-assisted patch; human-reviewed by Stan Shih (stantheman0128) before publish.

Verification / Evidence

Windows 11, fake binary harness (same argv-preservation cases as #214 discussion):

# Before (origin/main npm/index.js with execFileSync):
#   exit 3 -> wrapper exits 1 + Node stack trace
#   exit 137 -> wrapper exits 1 + Node stack trace

# After (spawnSync + process.exitCode):
#   exit 3 -> 3
#   exit 137 -> 137
#   5/5 argv cases pass (nested quotes, backslashes, empty arg, shell metachars literal)
#   ENOENT -> single-line error, exit 1 (no stack)

go test ./...   # green

Published npm 0.21.0 tarball on registry also carries the #215 argv fix; this PR is only the exit-code half.

What was not tested

  • Live npx zeabur against a remote Zeabur API (local fake-binary harness only).

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

execFileSync throws when the binary exits non-zero, so `npx zeabur`
printed a Node stack trace and always exited 1. That hides the exit
code that `service exec` and `server exec` deliberately return from
the remote command, which breaks scripting and CI usage.

spawnSync returns the status instead of throwing, so the wrapper can
forward it unchanged and report a spawn failure in a single line.

Co-authored-by: Cursor <[email protected]>
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.

1 participant