Skip to content

Commit 2178227

Browse files
committed
src: use node:moduleName as builtin module filename
This change allows for easier recognition of builtin modules in stack traces. Refs: #11893 PR-URL: #35498 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Zeyu Yang <[email protected]>
1 parent 19f1451 commit 2178227

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+306
-304
lines changed

lib/assert.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const {
3030
NumberIsNaN,
3131
RegExpPrototypeTest,
3232
String,
33+
StringPrototypeSlice,
34+
StringPrototypeStartsWith,
3335
} = primordials;
3436

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

291293
// Skip Node.js modules!
292-
if (filename.endsWith('.js') &&
293-
NativeModule.exists(filename.slice(0, -3))) {
294+
if (StringPrototypeStartsWith(filename, 'node:') &&
295+
NativeModule.exists(StringPrototypeSlice(filename, 5))) {
294296
errorCache.set(identifier, undefined);
295297
return;
296298
}

lib/internal/util/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]/g;
183183
const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
184184
const numberRegExp = /^(0|[1-9][0-9]*)$/;
185185

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

189189
const classRegExp = /^(\s+[^(]*?)\s*{/;

src/node_native_module.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ MaybeLocal<Function> NativeModuleLoader::LookupAndCompile(
260260
return {};
261261
}
262262

263-
std::string filename_s = id + std::string(".js");
263+
std::string filename_s = std::string("node:") + id;
264264
Local<String> filename =
265265
OneByteString(isolate, filename_s.c_str(), filename_s.size());
266266
Local<Integer> line_offset = Integer::New(isolate, 0);

test/message/assert_throws_stack.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
assert.js:*
1+
node:assert:*
22
throw err;
33
^
44

@@ -20,8 +20,8 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
2020
code: 'ERR_ASSERTION',
2121
actual: Error: foo
2222
at assert.throws.bar (*assert_throws_stack.js:*)
23-
at getActual (assert.js:*)
24-
at Function.throws (assert.js:*)
23+
at getActual (node:assert:*)
24+
at Function.throws (node:assert:*)
2525
at Object.<anonymous> (*assert_throws_stack.js:*:*)
2626
at *
2727
at *
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Error: test
22
at one (*fixtures*async-error.js:4:9)
33
at two (*fixtures*async-error.js:17:9)
4-
at processTicksAndRejections (internal/process/task_queues.js:*:*)
4+
at processTicksAndRejections (node:internal/process/task_queues:*:*)
55
at async three (*fixtures*async-error.js:20:3)
66
at async four (*fixtures*async-error.js:24:3)
77
at async main (*message*async_error_nexttick_main.js:7:5)

test/message/core_line_numbers.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
punycode.js:42
1+
node:punycode:42
22
throw new RangeError(errors[type]);
33
^
44

55
RangeError: Invalid input
6-
at error (punycode.js:42:8)
7-
at Object.decode (punycode.js:*:*)
6+
at error (node:punycode:42:8)
7+
at Object.decode (node:punycode:*:*)
88
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
9-
at Module._compile (internal/modules/cjs/loader.js:*:*)
10-
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
11-
at Module.load (internal/modules/cjs/loader.js:*:*)
12-
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
13-
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
14-
at internal/main/run_main_module.js:*:*
9+
at Module._compile (node:internal/modules/cjs/loader:*:*)
10+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
11+
at Module.load (node:internal/modules/cjs/loader:*:*)
12+
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
13+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
14+
at node:internal/main/run_main_module:*:*

test/message/error_exit.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Exiting with code=1
2-
assert.js:*
2+
node:assert:*
33
throw new AssertionError(obj);
44
^
55

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

1010
at Object.<anonymous> (*test*message*error_exit.js:*:*)
11-
at Module._compile (internal/modules/cjs/loader.js:*:*)
12-
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
13-
at Module.load (internal/modules/cjs/loader.js:*:*)
14-
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
15-
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*)
16-
at internal/main/run_main_module.js:*:* {
11+
at Module._compile (node:internal/modules/cjs/loader:*:*)
12+
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*:*)
13+
at Module.load (node:internal/modules/cjs/loader:*:*)
14+
at Function.Module._load (node:internal/modules/cjs/loader:*:*)
15+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
16+
at node:internal/main/run_main_module:*:* {
1717
generatedMessage: true,
1818
code: 'ERR_ASSERTION',
1919
actual: 1,

test/message/error_with_nul.out

12 Bytes
Binary file not shown.

test/message/esm_display_syntax_error.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ await async () => 0;
33
^^^^^
44

55
SyntaxError: Unexpected reserved word
6-
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
7-
at async link (internal/modules/esm/module_job.js:*:*)
6+
at Loader.moduleStrategy (node:internal/modules/esm/translators:*:*)
7+
at async link (node:internal/modules/esm/module_job:*:*)

test/message/esm_display_syntax_error_import.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ file:///*/test/message/esm_display_syntax_error_import.mjs:5
22
notfound
33
^^^^^^^^
44
SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-exports.mjs' does not provide an export named 'notfound'
5-
at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*)
6-
at async ModuleJob.run (internal/modules/esm/module_job.js:*:*)
7-
at async Loader.import (internal/modules/esm/loader.js:*:*)
8-
at async Object.loadESM (internal/process/esm_loader.js:*:*)
5+
at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*)
6+
at async ModuleJob.run (node:internal/modules/esm/module_job:*:*)
7+
at async Loader.import (node:internal/modules/esm/loader:*:*)
8+
at async Object.loadESM (node:internal/process/esm_loader:*:*)

0 commit comments

Comments
 (0)