From 5b5898ac86ea7d91e2403dcbddca2d9be7a98590 Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Sun, 26 Feb 2023 22:33:06 +0530 Subject: [PATCH] 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 Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Colin Ihrig --- lib/internal/debugger/inspect.js | 4 ++-- lib/internal/main/repl.js | 5 ++--- src/node.cc | 15 ++++++--------- test/parallel/test-snapshot-basic.js | 2 +- test/parallel/test-snapshot-error.js | 2 +- test/parallel/test-snapshot-incompatible.js | 2 +- test/sequential/test-debugger-invalid-args.js | 2 +- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index 039d33811d1a9d..24e5c0bd401f01 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -45,6 +45,7 @@ const { exitCodes: { kGenericUserError, kNoFailure, + kInvalidCommandLineArgument, }, } = internalBinding('errors'); @@ -339,8 +340,7 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2), ` ${invokedAs} :\n` + ` ${invokedAs} --port=\n` + ` ${invokedAs} -p \n`); - // TODO(joyeecheung): should be kInvalidCommandLineArgument. - process.exit(kGenericUserError); + process.exit(kInvalidCommandLineArgument); } const options = parseArgv(argv); diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index c371706b352c82..29fcd33d9030f1 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -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'); diff --git a/src/node.cc b/src/node.cc index 0d5162dde5da88..3f1b28a8a1815f 100644 --- a/src/node.cc +++ b/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 read_data = std::make_unique(); 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(); diff --git a/test/parallel/test-snapshot-basic.js b/test/parallel/test-snapshot-basic.js index d0796ee1a4290f..9bcf3025011315 100644 --- a/test/parallel/test-snapshot-basic.js +++ b/test/parallel/test-snapshot-basic.js @@ -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'); } diff --git a/test/parallel/test-snapshot-error.js b/test/parallel/test-snapshot-error.js index a68a4e0bd0cd79..32f41244c725e2 100644 --- a/test/parallel/test-snapshot-error.js +++ b/test/parallel/test-snapshot-error.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'))); } diff --git a/test/parallel/test-snapshot-incompatible.js b/test/parallel/test-snapshot-incompatible.js index 44447df13c6f7c..d90c791ac28676 100644 --- a/test/parallel/test-snapshot-incompatible.js +++ b/test/parallel/test-snapshot-incompatible.js @@ -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); } { diff --git a/test/sequential/test-debugger-invalid-args.js b/test/sequential/test-debugger-invalid-args.js index b137ed04255341..a0c42cac4d466a 100644 --- a/test/sequential/test-debugger-invalid-args.js +++ b/test/sequential/test-debugger-invalid-args.js @@ -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());