Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a28ddd4

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
module: do not wrap module._load when tracing is not enabled
This prevents clobbering the stack traces with another internal frame and removes the unnecessary hoops from step-debugging. PR-URL: #61479 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent da93e21 commit a28ddd4
Copy full SHA for a28ddd4

15 files changed

+21-46Lines changed: 21 additions & 46 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,21 @@ let statCache = null;
238238
function wrapModuleLoad(request, parent, isMain) {
239239
const logLabel = `[${parent?.id || ''}] [${request}]`;
240240
const traceLabel = `require('${request}')`;
241+
const channel = onRequire();
241242

242243
startTimer(logLabel, traceLabel);
243244

244245
try {
245-
return onRequire().traceSync(Module._load, {
246-
__proto__: null,
247-
parentFilename: parent?.filename,
248-
id: request,
249-
}, Module, request, parent, isMain);
246+
if (channel.hasSubscribers) {
247+
return onRequire().traceSync(Module._load, {
248+
__proto__: null,
249+
parentFilename: parent?.filename,
250+
id: request,
251+
}, Module, request, parent, isMain);
252+
}
253+
// No subscribers, skip the wrapping to avoid clobbering stack traces
254+
// and debugging steps.
255+
return Module._load(request, parent, isMain);
250256
} finally {
251257
endTimer(logLabel, traceLabel);
252258
}
Collapse file

‎test/fixtures/console/console.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/console/console.snapshot
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ Trace: foo
77
at *
88
at *
99
at *
10-
at *
Collapse file

‎test/fixtures/errors/force_colors.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/errors/force_colors.snapshot
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ Error: Should include grayed stack trace
1111
 at *
1212
 at *
1313
 at *
14-
 at *
1514

1615
Node.js *
Collapse file

‎test/fixtures/errors/promise_unhandled_warn_with_error.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/errors/promise_unhandled_warn_with_error.snapshot
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
at *
88
at *
99
at *
10-
at *
1110
(Use `* --trace-warnings ...` to show where the warning was created)
1211
(node:*) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https:*nodejs.org*api*cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
Collapse file

‎test/fixtures/errors/unhandled_promise_trace_warnings.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/errors/unhandled_promise_trace_warnings.snapshot
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
at *
1212
at *
1313
at *
14-
at *
1514
(node:*) Error: This was rejected
1615
at *
1716
at *
@@ -21,7 +20,6 @@
2120
at *
2221
at *
2322
at *
24-
at *
2523
(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
2624
at *
2725
at *
Collapse file

‎test/fixtures/source-map/output/source_map_assert_source_line.snapshot‎

Copy file name to clipboardExpand all lines: test/fixtures/source-map/output/source_map_assert_source_line.snapshot
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
1010
*
1111
*
1212
*
13-
*
1413
generatedMessage: true,
1514
code: 'ERR_ASSERTION',
1615
actual: false,
Collapse file

‎test/message/assert_throws_stack.out‎

Copy file name to clipboardExpand all lines: test/message/assert_throws_stack.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
1717
at *
1818
at *
1919
at *
20-
at *
2120
at * {
2221
generatedMessage: true,
2322
code: 'ERR_ASSERTION',
Collapse file

‎test/message/internal_assert.out‎

Copy file name to clipboardExpand all lines: test/message/internal_assert.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1313
at *
1414
at *
1515
at *
16-
at *
1716
at * {
1817
code: 'ERR_INTERNAL_ASSERTION'
1918
}
Collapse file

‎test/message/internal_assert_fail.out‎

Copy file name to clipboardExpand all lines: test/message/internal_assert_fail.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Please open an issue with this stack trace at https://github.com/nodejs/node/iss
1414
at *
1515
at *
1616
at *
17-
at *
1817
at * {
1918
code: 'ERR_INTERNAL_ASSERTION'
2019
}
Collapse file

‎test/message/util-inspect-error-cause.out‎

Copy file name to clipboardExpand all lines: test/message/util-inspect-error-cause.out
+10-20Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Error: Number error cause
66
at *
77
at *
88
at *
9-
at *
109
at * {
1110
[cause]: 42
1211
}
@@ -18,7 +17,6 @@ Error: Object cause
1817
at *
1918
at *
2019
at *
21-
at *
2220
at * {
2321
[cause]: {
2422
message: 'Unique',
@@ -35,7 +33,6 @@ Error: undefined cause
3533
at *
3634
at *
3735
at *
38-
at *
3936
at * {
4037
[cause]: undefined
4138
}
@@ -47,7 +44,6 @@ Error: cause that throws
4744
at *
4845
at *
4946
at *
50-
at *
5147
at * {
5248
[cause]: [Getter]
5349
}
@@ -57,7 +53,7 @@ RangeError: New Stack Frames
5753
[cause]: FoobarError: Individual message
5854
at *
5955
*[90m at *[39m
60-
*[90m ... 6 lines matching cause stack trace ...*[39m
56+
*[90m ... 5 lines matching cause stack trace ...*[39m
6157
*[90m at *[39m {
6258
status: *[32m'Feeling good'*[39m,
6359
extraProperties: *[32m'Yes!'*[39m,
@@ -70,18 +66,17 @@ RangeError: New Stack Frames
7066
*[90m at *[39m
7167
*[90m at *[39m
7268
*[90m at *[39m
73-
*[90m at *[39m
7469
}
7570
}
7671
Error: Stack causes
7772
at *
7873
*[90m at *[39m
79-
*[90m ... 6 lines matching cause stack trace ...*[39m
74+
*[90m ... 5 lines matching cause stack trace ...*[39m
8075
*[90m at *[39m {
8176
[cause]: FoobarError: Individual message
8277
at *
8378
*[90m at *[39m
84-
*[90m ... 6 lines matching cause stack trace ...*[39m
79+
*[90m ... 5 lines matching cause stack trace ...*[39m
8580
*[90m at *[39m {
8681
status: *[32m'Feeling good'*[39m,
8782
extraProperties: *[32m'Yes!'*[39m,
@@ -94,7 +89,6 @@ Error: Stack causes
9489
*[90m at *[39m
9590
*[90m at *[39m
9691
*[90m at *[39m
97-
*[90m at *[39m
9892
}
9993
}
10094
RangeError: New Stack Frames
@@ -103,12 +97,12 @@ RangeError: New Stack Frames
10397
[cause]: Error: Stack causes
10498
at *
10599
*[90m at *[39m
106-
*[90m ... 6 lines matching cause stack trace ...*[39m
100+
*[90m ... 5 lines matching cause stack trace ...*[39m
107101
*[90m at *[39m {
108102
[cause]: FoobarError: Individual message
109103
at *
110104
*[90m at *[39m
111-
*[90m ... 6 lines matching cause stack trace ...*[39m
105+
*[90m ... 5 lines matching cause stack trace ...*[39m
112106
*[90m at *[39m {
113107
status: *[32m'Feeling good'*[39m,
114108
extraProperties: *[32m'Yes!'*[39m,
@@ -121,7 +115,6 @@ RangeError: New Stack Frames
121115
*[90m at *[39m
122116
*[90m at *[39m
123117
*[90m at *[39m
124-
*[90m at *[39m
125118
}
126119
}
127120
}
@@ -131,7 +124,7 @@ RangeError: New Stack Frames
131124
[cause]: FoobarError: Individual message
132125
at *
133126
at *
134-
... 6 lines matching cause stack trace ...
127+
... 5 lines matching cause stack trace ...
135128
at * {
136129
status: 'Feeling good',
137130
extraProperties: 'Yes!',
@@ -144,18 +137,17 @@ RangeError: New Stack Frames
144137
at *
145138
at *
146139
at *
147-
at *
148140
}
149141
}
150142
Error: Stack causes
151143
at *
152144
at *
153-
... 6 lines matching cause stack trace ...
145+
... 5 lines matching cause stack trace ...
154146
at * {
155147
[cause]: FoobarError: Individual message
156148
at *
157149
at *
158-
... 6 lines matching cause stack trace ...
150+
... 5 lines matching cause stack trace ...
159151
at *
160152
status: 'Feeling good',
161153
extraProperties: 'Yes!',
@@ -168,7 +160,6 @@ Error: Stack causes
168160
at *
169161
at *
170162
at *
171-
at *
172163
}
173164
}
174165
RangeError: New Stack Frames
@@ -177,12 +168,12 @@ RangeError: New Stack Frames
177168
[cause]: Error: Stack causes
178169
at *
179170
at *
180-
... 6 lines matching cause stack trace ...
171+
... 5 lines matching cause stack trace ...
181172
at * {
182173
[cause]: FoobarError: Individual message
183174
at *
184175
at *
185-
... 6 lines matching cause stack trace ...
176+
... 5 lines matching cause stack trace ...
186177
at * {
187178
status: 'Feeling good',
188179
extraProperties: 'Yes!',
@@ -195,7 +186,6 @@ RangeError: New Stack Frames
195186
at *
196187
at *
197188
at *
198-
at *
199189
}
200190
}
201191
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.