Skip to content

Commit 5b5898a

Browse files
authored
lib,src: update exit codes as per todos
Refs: #44746 PR-URL: #45841 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 355bcbc commit 5b5898a

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

lib/internal/debugger/inspect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const {
4545
exitCodes: {
4646
kGenericUserError,
4747
kNoFailure,
48+
kInvalidCommandLineArgument,
4849
},
4950
} = internalBinding('errors');
5051

@@ -339,8 +340,7 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2),
339340
` ${invokedAs} <host>:<port>\n` +
340341
` ${invokedAs} --port=<port>\n` +
341342
` ${invokedAs} -p <pid>\n`);
342-
// TODO(joyeecheung): should be kInvalidCommandLineArgument.
343-
process.exit(kGenericUserError);
343+
process.exit(kInvalidCommandLineArgument);
344344
}
345345

346346
const options = parseArgv(argv);

lib/internal/main/repl.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const console = require('internal/console/global');
1616

1717
const { getOptionValue } = require('internal/options');
1818

19-
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
19+
const { exitCodes: { kInvalidCommandLineArgument } } = internalBinding('errors');
2020

2121
prepareMainThreadExecution();
2222

@@ -32,8 +32,7 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) {
3232
// If we can't write to stderr, we'd like to make this a noop,
3333
// so use console.error.
3434
console.error('Cannot specify --input-type for REPL');
35-
// TODO(joyeecheung): should be kInvalidCommandLineArgument.
36-
process.exit(kGenericUserError);
35+
process.exit(kInvalidCommandLineArgument);
3736
}
3837

3938
const esmLoader = require('internal/process/esm_loader');

src/node.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,7 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr,
11321132
"node:embedded_snapshot_main was specified as snapshot "
11331133
"entry point but Node.js was built without embedded "
11341134
"snapshot.\n");
1135-
// TODO(joyeecheung): should be kInvalidCommandLineArgument instead.
1136-
exit_code = ExitCode::kGenericUserError;
1135+
exit_code = ExitCode::kInvalidCommandLineArgument;
11371136
return exit_code;
11381137
}
11391138
} else {
@@ -1166,8 +1165,7 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr,
11661165
fprintf(stderr,
11671166
"Cannot open %s for writing a snapshot.\n",
11681167
snapshot_blob_path.c_str());
1169-
// TODO(joyeecheung): should be kStartupSnapshotFailure.
1170-
exit_code = ExitCode::kGenericUserError;
1168+
exit_code = ExitCode::kStartupSnapshotFailure;
11711169
}
11721170
return exit_code;
11731171
}
@@ -1183,17 +1181,16 @@ ExitCode LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
11831181
FILE* fp = fopen(filename.c_str(), "rb");
11841182
if (fp == nullptr) {
11851183
fprintf(stderr, "Cannot open %s", filename.c_str());
1186-
// TODO(joyeecheung): should be kStartupSnapshotFailure.
1187-
exit_code = ExitCode::kGenericUserError;
1184+
exit_code = ExitCode::kStartupSnapshotFailure;
11881185
return exit_code;
11891186
}
11901187
std::unique_ptr<SnapshotData> read_data = std::make_unique<SnapshotData>();
11911188
bool ok = SnapshotData::FromFile(read_data.get(), fp);
11921189
fclose(fp);
11931190
if (!ok) {
1194-
// If we fail to read the customized snapshot, simply exit with 1.
1195-
// TODO(joyeecheung): should be kStartupSnapshotFailure.
1196-
exit_code = ExitCode::kGenericUserError;
1191+
// If we fail to read the customized snapshot,
1192+
// simply exit with kStartupSnapshotFailure.
1193+
exit_code = ExitCode::kStartupSnapshotFailure;
11971194
return exit_code;
11981195
}
11991196
*snapshot_data_ptr = read_data.release();

test/parallel/test-snapshot-basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!process.config.variables.node_use_node_snapshot) {
2828
assert.match(
2929
child.stderr.toString(),
3030
/Node\.js was built without embedded snapshot/);
31-
assert.strictEqual(child.status, 1);
31+
assert.strictEqual(child.status, 9);
3232

3333
snapshotScript = fixtures.path('empty.js');
3434
}

test/parallel/test-snapshot-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const entry = fixtures.path('snapshot', 'error.js');
4747
console.log(child.status);
4848
console.log(stderr);
4949
console.log(child.stdout.toString());
50-
assert.strictEqual(child.status, 1);
50+
assert.strictEqual(child.status, 14);
5151
assert.match(stderr, /Cannot open/);
5252
assert(!fs.existsSync(path.join(tmpdir.path, 'snapshot.blob')));
5353
}

test/parallel/test-snapshot-incompatible.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const entry = fixtures.path('empty.js');
5252

5353
const stderr = child.stderr.toString().trim();
5454
assert.match(stderr, /Failed to load the startup snapshot/);
55-
assert.strictEqual(child.status, 1);
55+
assert.strictEqual(child.status, 14);
5656
}
5757

5858
{

test/sequential/test-debugger-invalid-args.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const assert = require('assert');
1111
(async () => {
1212
const cli = startCLI([]);
1313
const code = await cli.quit();
14-
assert.strictEqual(code, 1);
14+
assert.strictEqual(code, 9);
1515
assert.match(cli.output, /^Usage:/, 'Prints usage info');
1616
})().then(common.mustCall());
1717

0 commit comments

Comments
 (0)