Skip to content

Commit

Permalink
lib,src: update exit codes as per todos
Browse files Browse the repository at this point in the history
Refs: #44746
PR-URL: #45841
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
debadree25 committed Feb 26, 2023
1 parent 355bcbc commit 5b5898a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/internal/debugger/inspect.js
Expand Up @@ -45,6 +45,7 @@ const {
exitCodes: {
kGenericUserError,
kNoFailure,
kInvalidCommandLineArgument,
},
} = internalBinding('errors');

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

const options = parseArgv(argv);
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/main/repl.js
Expand Up @@ -16,7 +16,7 @@ const console = require('internal/console/global');

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

const { exitCodes: { kGenericUserError } } = internalBinding('errors');
const { exitCodes: { kInvalidCommandLineArgument } } = internalBinding('errors');

prepareMainThreadExecution();

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

const esmLoader = require('internal/process/esm_loader');
Expand Down
15 changes: 6 additions & 9 deletions src/node.cc
Expand Up @@ -1132,8 +1132,7 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr,
"node:embedded_snapshot_main was specified as snapshot "
"entry point but Node.js was built without embedded "
"snapshot.\n");
// TODO(joyeecheung): should be kInvalidCommandLineArgument instead.
exit_code = ExitCode::kGenericUserError;
exit_code = ExitCode::kInvalidCommandLineArgument;
return exit_code;
}
} else {
Expand Down Expand Up @@ -1166,8 +1165,7 @@ ExitCode GenerateAndWriteSnapshotData(const SnapshotData** snapshot_data_ptr,
fprintf(stderr,
"Cannot open %s for writing a snapshot.\n",
snapshot_blob_path.c_str());
// TODO(joyeecheung): should be kStartupSnapshotFailure.
exit_code = ExitCode::kGenericUserError;
exit_code = ExitCode::kStartupSnapshotFailure;
}
return exit_code;
}
Expand All @@ -1183,17 +1181,16 @@ ExitCode LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
FILE* fp = fopen(filename.c_str(), "rb");
if (fp == nullptr) {
fprintf(stderr, "Cannot open %s", filename.c_str());
// TODO(joyeecheung): should be kStartupSnapshotFailure.
exit_code = ExitCode::kGenericUserError;
exit_code = ExitCode::kStartupSnapshotFailure;
return exit_code;
}
std::unique_ptr<SnapshotData> read_data = std::make_unique<SnapshotData>();
bool ok = SnapshotData::FromFile(read_data.get(), fp);
fclose(fp);
if (!ok) {
// If we fail to read the customized snapshot, simply exit with 1.
// TODO(joyeecheung): should be kStartupSnapshotFailure.
exit_code = ExitCode::kGenericUserError;
// If we fail to read the customized snapshot,
// simply exit with kStartupSnapshotFailure.
exit_code = ExitCode::kStartupSnapshotFailure;
return exit_code;
}
*snapshot_data_ptr = read_data.release();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-snapshot-basic.js
Expand Up @@ -28,7 +28,7 @@ if (!process.config.variables.node_use_node_snapshot) {
assert.match(
child.stderr.toString(),
/Node\.js was built without embedded snapshot/);
assert.strictEqual(child.status, 1);
assert.strictEqual(child.status, 9);

snapshotScript = fixtures.path('empty.js');
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-snapshot-error.js
Expand Up @@ -47,7 +47,7 @@ const entry = fixtures.path('snapshot', 'error.js');
console.log(child.status);
console.log(stderr);
console.log(child.stdout.toString());
assert.strictEqual(child.status, 1);
assert.strictEqual(child.status, 14);
assert.match(stderr, /Cannot open/);
assert(!fs.existsSync(path.join(tmpdir.path, 'snapshot.blob')));
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-snapshot-incompatible.js
Expand Up @@ -52,7 +52,7 @@ const entry = fixtures.path('empty.js');

const stderr = child.stderr.toString().trim();
assert.match(stderr, /Failed to load the startup snapshot/);
assert.strictEqual(child.status, 1);
assert.strictEqual(child.status, 14);
}

{
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-debugger-invalid-args.js
Expand Up @@ -11,7 +11,7 @@ const assert = require('assert');
(async () => {
const cli = startCLI([]);
const code = await cli.quit();
assert.strictEqual(code, 1);
assert.strictEqual(code, 9);
assert.match(cli.output, /^Usage:/, 'Prints usage info');
})().then(common.mustCall());

Expand Down

0 comments on commit 5b5898a

Please sign in to comment.