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 49745cd

Browse filesBrowse files
committed
process: delay throwing an error using throwDeprecation
This makes sure all warnings that were triggered before a deprecation warning during the same tick are properly handled and logged. It also guarantees that users can not catch the error anymore. Fixes: #17871 PR-URL: #32312 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 5d06a37 commit 49745cd
Copy full SHA for 49745cd

File tree

Expand file treeCollapse file tree

2 files changed

+15
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/process/warning.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/warning.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ function emitWarning(warning, type, code, ctor) {
126126
if (warning.name === 'DeprecationWarning') {
127127
if (process.noDeprecation)
128128
return;
129-
if (process.throwDeprecation)
130-
throw warning;
129+
if (process.throwDeprecation) {
130+
// Delay throwing the error to guarantee that all former warnings were
131+
// properly logged.
132+
return process.nextTick(() => {
133+
throw warning;
134+
});
135+
}
131136
}
132137
process.nextTick(doEmitWarning, warning);
133138
}
Collapse file

‎test/parallel/test-process-warning.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-process-warning.js
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ function test4() {
3838
// process.emitWarning will throw when process.throwDeprecation is true
3939
// and type is `DeprecationWarning`.
4040
process.throwDeprecation = true;
41-
assert.throws(
42-
() => process.emitWarning('test', 'DeprecationWarning'),
43-
/^DeprecationWarning: test$/);
41+
process.once('uncaughtException', (err) => {
42+
assert.match(err.toString(), /^DeprecationWarning: test$/);
43+
});
44+
try {
45+
process.emitWarning('test', 'DeprecationWarning');
46+
} catch {
47+
assert.fail('Unreachable');
48+
}
4449
process.throwDeprecation = false;
4550
setImmediate(test5);
4651
}

0 commit comments

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