Skip to content

Commit 251e5ed

Browse files
committed
errors: assign error code to bootstrap_node created error
This does not use the internal/errors.js module because the error in question may actually be *caused* by an attempt to load internal/errors.js. This error should only be encountered in the case of a bug within Node.js itself. PR-URL: #11298 Ref: #11273 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 3769907 commit 251e5ed

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/api/errors.md

+10
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ found [here][online].
558558
encountered by [`http`][] or [`net`][] -- often a sign that a `socket.end()`
559559
was not properly called.
560560

561+
561562
<a id="nodejs-error-codes"></a>
562563
## Node.js Error Codes
563564

@@ -587,6 +588,14 @@ An error using the `'ERR_STDOUT_CLOSE'` code is thrown specifically when an
587588
attempt is made to close the `process.stdout` stream. By design, Node.js does
588589
not allow `stdout` or `stderr` Streams to be closed by user code.
589590

591+
<a id="ERR_UNKNOWN_BUILTIN_MODULE"></a>
592+
### ERR_UNKNOWN_BUILTIN_MODULE
593+
594+
The `'ERR_UNKNOWN_BUILTIN_MODULE'` error code is used to identify a specific
595+
kind of internal Node.js error that should not typically be triggered by user
596+
code. Instances of this error point to an internal bug within the Node.js
597+
binary itself.
598+
590599
<a id="ERR_UNKNOWN_STDIN_TYPE"></a>
591600
### ERR_UNKNOWN_STDIN_TYPE
592601

@@ -605,6 +614,7 @@ an attempt is made to launch a Node.js process with an unknown `stdout` or
605614
in user code, although it is not impossible. Occurrences of this error are most
606615
likely an indication of a bug within Node.js itself.
607616

617+
608618
[`fs.readdir`]: fs.html#fs_fs_readdir_path_options_callback
609619
[`fs.readFileSync`]: fs.html#fs_fs_readfilesync_file_options
610620
[`fs.unlink`]: fs.html#fs_fs_unlink_path_callback

lib/internal/bootstrap_node.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,13 @@
462462
}
463463

464464
if (!NativeModule.exists(id)) {
465-
throw new Error(`No such native module ${id}`);
465+
// Model the error off the internal/errors.js model, but
466+
// do not use that module given that it could actually be
467+
// the one causing the error if there's a bug in Node.js
468+
const err = new Error(`No such built-in module: ${id}`);
469+
err.code = 'ERR_UNKNOWN_BUILTIN_MODULE';
470+
err.name = 'Error [ERR_UNKNOWN_BUILTIN_MODULE]';
471+
throw err;
466472
}
467473

468474
process.moduleLoadList.push(`NativeModule ${id}`);

lib/internal/errors.js

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
8686
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
8787
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
8888
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
89+
E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);
8990
// Add new errors from here...
9091

9192
function invalidArgType(name, expected, actual) {

0 commit comments

Comments
 (0)