Skip to content

Commit 21930ef

Browse files
committed
improve error a bit
1 parent 7839cc1 commit 21930ef

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

ext/node/polyfills/process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Object.defineProperty(Process.prototype, "exitCode", {
437437
return ProcessExitCode;
438438
},
439439
set(code: number | string | null | undefined) {
440-
if (code != null) {
440+
if (!!code) {
441441
// This is looser than `denoOs.setExitCode` which requires exit code
442442
// to be decimal or string of a decimal, but Node accept eg. 0x10.
443443
code = parseInt(code) || 0;

runtime/js/30_os.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ function getExitCode() {
104104
function setExitCode(value) {
105105
const code = NumberParseInt(value, 10) || undefined;
106106
if (typeof code !== "number") {
107-
throw new TypeError("Exit code must be a number.");
107+
throw new TypeError(
108+
`Exit code must be a number, got: ${code} (${typeof code}).`,
109+
);
108110
}
109111
op_set_exit_code(code);
110112
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo hello
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
'use strict';
3+
const { spawn } = require('child_process');
4+
// Reference the object to invoke the getter
5+
process.stdin;
6+
setTimeout(() => {
7+
let ok = false;
8+
const child = spawn(process.env.SHELL || '/bin/sh',
9+
[], { stdio: ['inherit', 'pipe'] });
10+
child.stdout.on('data', () => {
11+
ok = true;
12+
});
13+
child.on('close', () => {
14+
process.exit(ok ? 0 : -1);
15+
});
16+
}, 100);

0 commit comments

Comments
 (0)