mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
lib,src: update exit codes as per todos
Refs: https://github.com/nodejs/node/pull/44746 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
355bcbc33d
commit
5b5898ac86
7 changed files with 14 additions and 18 deletions
|
@ -45,6 +45,7 @@ const {
|
|||
exitCodes: {
|
||||
kGenericUserError,
|
||||
kNoFailure,
|
||||
kInvalidCommandLineArgument,
|
||||
},
|
||||
} = internalBinding('errors');
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -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');
|
||||
|
|
15
src/node.cc
15
src/node.cc
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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')));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue