fix(cli): coerce ServerSupervisor exit code to number — prevents TypeError on Node.js v24 (#3748) (#3750)

Node.js v24 added strict type checking to process.exit() and throws
TypeError [ERR_INVALID_ARG_TYPE] when given a non-number. The spawn
'error' event passes err.code (e.g. 'ENOENT') — a string, not a number
— via `err.code ?? -1` (nullish coalescing doesn't help since 'ENOENT'
is not null/undefined). handleExit() now normalises the code to a number
at the top; the 'error' callback passes -1 unconditionally.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-13 01:15:53 -03:00
committed by GitHub
parent 62a0f6a542
commit 33667fcf3a
3 changed files with 45 additions and 4 deletions

View File

@@ -42,17 +42,20 @@ export class ServerSupervisor {
});
}
this.child.on("error", (err) => this.handleExit(err.code ?? -1, err));
this.child.on("error", (err) => this.handleExit(-1, err));
this.child.on("exit", (code) => this.handleExit(code));
return this.child;
}
handleExit(code) {
// Node.js v24+ requires process.exit() to receive a number. Spawn-error events
// deliver err.code (a string like 'ENOENT') via the 'error' listener; normalise here.
const exitCode = typeof code === "number" ? code : null;
cleanupPidFile("server");
if (this.isShuttingDown || code === 0) {
process.exit(code || 0);
if (this.isShuttingDown || exitCode === 0) {
process.exit(exitCode ?? 0);
return;
}
@@ -71,7 +74,7 @@ export class ServerSupervisor {
}
}
this.dumpCrashLog();
process.exit(code ?? 1);
process.exit(exitCode ?? 1);
return;
}