Skip to content

Commit

Permalink
src: use node:moduleName as builtin module filename
Browse files Browse the repository at this point in the history
This change allows for easier recognition of builtin modules in stack
traces.

Refs: #11893

PR-URL: #35498
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
  • Loading branch information
targos committed Oct 7, 2020
1 parent 19f1451 commit 2178227
Show file tree
Hide file tree
Showing 47 changed files with 306 additions and 304 deletions.
6 changes: 4 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const {
NumberIsNaN,
RegExpPrototypeTest,
String,
StringPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;

const { Buffer } = require('buffer');
Expand Down Expand Up @@ -289,8 +291,8 @@ function getErrMessage(message, fn) {
identifier = `${filename}${line}${column}`;

// Skip Node.js modules!
if (filename.endsWith('.js') &&
NativeModule.exists(filename.slice(0, -3))) {
if (StringPrototypeStartsWith(filename, 'node:') &&
NativeModule.exists(StringPrototypeSlice(filename, 5))) {
errorCache.set(identifier, undefined);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]/g;
const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
const numberRegExp = /^(0|[1-9][0-9]*)$/;

const coreModuleRegExp = /^ at (?:[^/\\(]+ \(|)((?<![/\\]).+)\.js:\d+:\d+\)?$/;
const coreModuleRegExp = /^ at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/;
const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g;

const classRegExp = /^(\s+[^(]*?)\s*{/;
Expand Down
2 changes: 1 addition & 1 deletion src/node_native_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
return {};
}

std::string filename_s = id + std::string(".js");
std::string filename_s = std::string("node:") + id;
Local<String> filename =
OneByteString(isolate, filename_s.c_str(), filename_s.size());
Local<Integer> line_offset = Integer::New(isolate, 0);
Expand Down
6 changes: 3 additions & 3 deletions test/message/assert_throws_stack.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
assert.js:*
node:assert:*
throw err;
^

Expand All @@ -20,8 +20,8 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
code: 'ERR_ASSERTION',
actual: Error: foo
at assert.throws.bar (*assert_throws_stack.js:*)
at getActual (assert.js:*)
at Function.throws (assert.js:*)
at getActual (node:assert:*)
at Function.throws (node:assert:*)
at Object.<anonymous> (*assert_throws_stack.js:*:*)
at *
at *
Expand Down
2 changes: 1 addition & 1 deletion test/message/async_error_nexttick_main.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Error: test
at one (*fixtures*async-error.js:4:9)
at two (*fixtures*async-error.js:17:9)
at processTicksAndRejections (internal/process/task_queues.js:*:*)
at processTicksAndRejections (node:internal/process/task_queues:*:*)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_nexttick_main.js:7:5)
18 changes: 9 additions & 9 deletions test/message/core_line_numbers.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
punycode.js:42
node:punycode:42
throw new RangeError(errors[type]);
^

RangeError: Invalid input
at error (punycode.js:42:8)
at Object.decode (punycode.js:*:*)
at error (node:punycode:42:8)
at Object.decode (node:punycode:*:*)
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
14 changes: 7 additions & 7 deletions test/message/error_exit.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Exiting with code=1
assert.js:*
node:assert:*
throw new AssertionError(obj);
^

Expand All @@ -8,12 +8,12 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1 !== 2

at Object.<anonymous> (*test*message*error_exit.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:* {
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,
Expand Down
Binary file modified test/message/error_with_nul.out
Binary file not shown.
4 changes: 2 additions & 2 deletions test/message/esm_display_syntax_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ await async () => 0;
^^^^^

SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
at async link (internal/modules/esm/module_job.js:*:*)
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
at async link (node:internal/modules/esm/module_job:*:*)
8 changes: 4 additions & 4 deletions test/message/esm_display_syntax_error_import.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ file:///*/test/message/esm_display_syntax_error_import.mjs:5
notfound
^^^^^^^^
SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-exports.mjs' does not provide an export named 'notfound'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*)
at async ModuleJob.run (internal/modules/esm/module_job.js:*:*)
at async Loader.import (internal/modules/esm/loader.js:*:*)
at async Object.loadESM (internal/process/esm_loader.js:*:*)
at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*)
at async ModuleJob.run (node:internal/modules/esm/module_job:*:*)
at async Loader.import (node:internal/modules/esm/loader:*:*)
at async Object.loadESM (node:internal/process/esm_loader:*:*)
8 changes: 4 additions & 4 deletions test/message/esm_display_syntax_error_import_module.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1
import { foo, notfound } from './module-named-exports.mjs';
^^^^^^^^
SyntaxError: The requested module './module-named-exports.mjs' does not provide an export named 'notfound'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*)
at async ModuleJob.run (internal/modules/esm/module_job.js:*:*)
at async Loader.import (internal/modules/esm/loader.js:*:*)
at async Object.loadESM (internal/process/esm_loader.js:*:*)
at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*)
at async ModuleJob.run (node:internal/modules/esm/module_job:*:*)
at async Loader.import (node:internal/modules/esm/loader:*:*)
at async Object.loadESM (node:internal/process/esm_loader:*:*)
2 changes: 1 addition & 1 deletion test/message/esm_display_syntax_error_module.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ await async () => 0;
^^^^^^^^^^^^^

SyntaxError: Malformed arrow function parameter list
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
22 changes: 11 additions & 11 deletions test/message/esm_loader_not_found.out
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `* --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:*
node:internal/process/esm_loader:*
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from *
at new NodeError (internal/errors.js:*:*)
at packageResolve (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*)
at Loader.resolve (internal/modules/esm/loader.js:*:*)
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*)
at Loader.import (internal/modules/esm/loader.js:*:*)
at internal/process/esm_loader.js:*:*
at initializeLoader (internal/process/esm_loader.js:*:*)
at Object.loadESM (internal/process/esm_loader.js:*:*) {
at new NodeError (node:internal/errors:*:*)
at packageResolve (node:internal/modules/esm/resolve:*:*)
at moduleResolve (node:internal/modules/esm/resolve:*:*)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:*:*)
at Loader.resolve (node:internal/modules/esm/loader:*:*)
at Loader.getModuleJob (node:internal/modules/esm/loader:*:*)
at Loader.import (node:internal/modules/esm/loader:*:*)
at node:internal/process/esm_loader:*:*
at initializeLoader (node:internal/process/esm_loader:*:*)
at Object.loadESM (node:internal/process/esm_loader:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
18 changes: 9 additions & 9 deletions test/message/esm_loader_not_found_cjs_hint_bare.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
internal/process/esm_loader.js:*
node:internal/process/esm_loader:*
internalBinding('errors').triggerUncaughtException(
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*fixtures*node_modules*some_module*obj' imported from *test*fixtures*esm_loader_not_found_cjs_hint_bare.mjs
Did you mean to import some_module/obj.js?
at new NodeError (internal/errors.js:*:*)
at finalizeResolution (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*)
at Loader.resolve (internal/modules/esm/loader.js:*:*)
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:*:*)
at link (internal/modules/esm/module_job.js:*:*) {
at new NodeError (node:internal/errors:*:*)
at finalizeResolution (node:internal/modules/esm/resolve:*:*)
at moduleResolve (node:internal/modules/esm/resolve:*:*)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:*:*)
at Loader.resolve (node:internal/modules/esm/loader:*:*)
at Loader.getModuleJob (node:internal/modules/esm/loader:*:*)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:*:*)
at link (node:internal/modules/esm/module_job:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
22 changes: 11 additions & 11 deletions test/message/esm_loader_not_found_cjs_hint_relative.out
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `* --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:*
node:internal/process/esm_loader:*
internalBinding('errors').triggerUncaughtException(
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*common*fixtures' imported from *
Did you mean to import ./test/common/fixtures.js?
at new NodeError (internal/errors.js:*:*)
at finalizeResolution (internal/modules/esm/resolve.js:*:*)
at moduleResolve (internal/modules/esm/resolve.js:*:*)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:*:*)
at Loader.resolve (internal/modules/esm/loader.js:*:*)
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*)
at Loader.import (internal/modules/esm/loader.js:*:*)
at internal/process/esm_loader.js:*:*
at initializeLoader (internal/process/esm_loader.js:*:*)
at Object.loadESM (internal/process/esm_loader.js:*:*) {
at new NodeError (node:internal/errors:*:*)
at finalizeResolution (node:internal/modules/esm/resolve:*:*)
at moduleResolve (node:internal/modules/esm/resolve:*:*)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:*:*)
at Loader.resolve (node:internal/modules/esm/loader:*:*)
at Loader.getModuleJob (node:internal/modules/esm/loader:*:*)
at Loader.import (node:internal/modules/esm/loader:*:*)
at node:internal/process/esm_loader:*:*
at initializeLoader (node:internal/process/esm_loader:*:*)
at Object.loadESM (node:internal/process/esm_loader:*:*) {
code: 'ERR_MODULE_NOT_FOUND'
}
4 changes: 2 additions & 2 deletions test/message/esm_loader_syntax_error.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ await async () => 0;
^^^^^^^^^^^^^

SyntaxError: Malformed arrow function parameter list
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
at async link (internal/modules/esm/module_job.js:*:*)
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
at async link (node:internal/modules/esm/module_job:*:*)
42 changes: 21 additions & 21 deletions test/message/eval_messages.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
with(this){__filename}
^^^^
SyntaxError: Strict mode code may not include a with statement
at new Script (vm.js:*:*)
at createScript (vm.js:*:*)
at Object.runInThisContext (vm.js:*:*)
at internal/process/execution.js:*:*
at new Script (node:vm:*:*)
at createScript (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at evalScript (internal/process/execution.js:*:*)
at internal/main/eval_string.js:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
42
42
[eval]:1
Expand All @@ -18,38 +18,38 @@ throw new Error("hello")

Error: hello
at [eval]:1:7
at Script.runInThisContext (vm.js:*:*)
at Object.runInThisContext (vm.js:*:*)
at internal/process/execution.js:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at evalScript (internal/process/execution.js:*:*)
at internal/main/eval_string.js:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*

[eval]:1
throw new Error("hello")
^

Error: hello
at [eval]:1:7
at Script.runInThisContext (vm.js:*:*)
at Object.runInThisContext (vm.js:*:*)
at internal/process/execution.js:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at evalScript (internal/process/execution.js:*:*)
at internal/main/eval_string.js:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*
100
[eval]:1
var x = 100; y = x;
^

ReferenceError: y is not defined
at [eval]:1:16
at Script.runInThisContext (vm.js:*:*)
at Object.runInThisContext (vm.js:*:*)
at internal/process/execution.js:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at evalScript (internal/process/execution.js:*:*)
at internal/main/eval_string.js:*:*
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*

[eval]:1
var ______________________________________________; throw 10
Expand Down
18 changes: 9 additions & 9 deletions test/message/events_unhandled_error_common_trace.out
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
events.js:*
node:events:*
throw er; // Unhandled 'error' event
^

Error: foo:bar
at bar (*events_unhandled_error_common_trace.js:*:*)
at foo (*events_unhandled_error_common_trace.js:*:*)
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event at:
at quux (*events_unhandled_error_common_trace.js:*:*)
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Module._compile (node:internal/modules/cjs/loader:*:*)
[... lines matching original stack trace ...]
at internal/main/run_main_module.js:*:*
at node:internal/main/run_main_module:*:*
16 changes: 8 additions & 8 deletions test/message/events_unhandled_error_nexttick.out
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
events.js:*
node:events:*
throw er; // Unhandled 'error' event
^

Error
at Object.<anonymous> (*events_unhandled_error_nexttick.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
at internal/main/run_main_module.js:*:*
at Module._compile (node:internal/modules/cjs/loader:*:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
at Module.load (node:internal/modules/cjs/loader:*:*)
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
at node:internal/main/run_main_module:*:*
Emitted 'error' event at:
at *events_unhandled_error_nexttick.js:*:*
at processTicksAndRejections (internal/process/task_queues.js:*:*)
at processTicksAndRejections (node:internal/process/task_queues:*:*)
Loading

0 comments on commit 2178227

Please sign in to comment.