Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: delay throwing an error using throwDeprecation #32312

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/internal/process/warning.js
Expand Up @@ -118,8 +118,13 @@ function emitWarning(warning, type, code, ctor) {
if (warning.name === 'DeprecationWarning') {
if (process.noDeprecation)
return;
if (process.throwDeprecation)
throw warning;
if (process.throwDeprecation) {
// Delay throwing the error to guarantee that all former warnings were
// properly logged.
return process.nextTick(() => {
throw warning;
});
}
}
process.nextTick(doEmitWarning(warning));
}
Expand Down
11 changes: 8 additions & 3 deletions test/parallel/test-process-warning.js
Expand Up @@ -38,9 +38,14 @@ function test4() {
// process.emitWarning will throw when process.throwDeprecation is true
// and type is `DeprecationWarning`.
process.throwDeprecation = true;
assert.throws(
() => process.emitWarning('test', 'DeprecationWarning'),
/^DeprecationWarning: test$/);
process.once('uncaughtException', (err) => {
assert.match(err.toString(), /^DeprecationWarning: test$/);
});
try {
process.emitWarning('test', 'DeprecationWarning');
} catch {
assert.fail('Unreachable');
}
process.throwDeprecation = false;
setImmediate(test5);
}
Expand Down