Skip to content

node:child_process — execSync/execFileSync do not throw on non-zero exit #1938

Description

@proggeramlug

Summary

execSync / execFileSync do not throw on a non-zero exit. Node throws an Error (with the command output attached) when the child exits non-zero:

try { cp.execSync("exit 4"); } catch (e) {
  // Object.keys(e) → status, signal, output, pid, stdout, stderr
  // e.status === 4
}

Today (perry 0.5.1029) js_child_process_exec_sync returns the stdout string regardless of exit code, and js_child_process_exec_file_sync likewise never throws.

What to do

  • On non-zero exit, throw an Error carrying status (exit code), signal, pid, output ([null, stdout, stderr]), stdout, stderr, and cmd.
  • The zero-exit path keeps returning stdout (Buffer by default, string with an encoding option).

Compat note: this changes today's lenient behavior (always returns stdout), so existing Perry programs that call execSync on commands that can fail without try/catch will start throwing — matching Node, but worth flagging at merge. Pairs with the exec error-shape and encoding issues.

Parent: #1780. perry 0.5.1029.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions