Skip to main content

set_exit_code

Function set_exit_code 

Source
pub fn set_exit_code(val: &Value) -> Result<(), String>
Expand description

The process.exitCode setter, ported from Node’s lib/internal/bootstrap/node.js accessor:

set(code) {
  if (code !== null && code !== undefined) {
    let value = code;
    if (typeof code === 'string' && code !== '' &&
      NumberIsNaN((value = Number(code)))) {
      value = code;
    }
    validateInteger(value, 'code');
    …
  } else { /* clear */ }
}

So a NUMERIC string is accepted and coerced ("3" → 3, "0x10" → 16, " " → 0), a non-numeric or empty string keeps its string identity and fails validateInteger as a TYPE error, a non-integer number fails as a RANGE error, and null/undefined clear the slot. Verified on node v26.7.0: process.exitCode = "0x10" exits 16, = 3.7 throws ERR_OUT_OF_RANGE, = "" throws ERR_INVALID_ARG_TYPE, = " " exits 0.