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 e48ec70

Browse filesBrowse files
addaleaxcodebytere
authored andcommitted
domain: improve deprecation warning text for DEP0097
Because the following gives basically no actionable information on its own, neither in the error message nor in the stack trace: (node:3187) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead. at emitMakeCallbackDeprecation (domain.js:123:13) at process.topLevelDomainCallback (domain.js:135:5) at process.callbackTrampoline (internal/async_hooks.js:124:14) PR-URL: #36136 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent d8fcf2c commit e48ec70
Copy full SHA for e48ec70

File tree

Expand file treeCollapse file tree

2 files changed

+17
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-6
lines changed
Open diff view settings
Collapse file

‎lib/domain.js‎

Copy file name to clipboardExpand all lines: lib/domain.js
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,23 @@ process.setUncaughtExceptionCaptureCallback = function(fn) {
124124

125125

126126
let sendMakeCallbackDeprecation = false;
127-
function emitMakeCallbackDeprecation() {
127+
function emitMakeCallbackDeprecation({ target, method }) {
128128
if (!sendMakeCallbackDeprecation) {
129129
process.emitWarning(
130130
'Using a domain property in MakeCallback is deprecated. Use the ' +
131131
'async_context variant of MakeCallback or the AsyncResource class ' +
132-
'instead.', 'DeprecationWarning', 'DEP0097');
132+
'instead. ' +
133+
`(Triggered by calling ${method?.name ?? '<anonymous>'} ` +
134+
`on ${target?.constructor?.name}.)`,
135+
'DeprecationWarning', 'DEP0097');
133136
sendMakeCallbackDeprecation = true;
134137
}
135138
}
136139

137140
function topLevelDomainCallback(cb, ...args) {
138141
const domain = this.domain;
139142
if (exports.active && domain)
140-
emitMakeCallbackDeprecation();
143+
emitMakeCallbackDeprecation({ target: this, method: cb });
141144

142145
if (domain)
143146
domain.enter();
Collapse file

‎test/addons/make-callback-domain-warning/test.js‎

Copy file name to clipboardExpand all lines: test/addons/make-callback-domain-warning/test.js
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const domain = require('domain');
66
const binding = require(`./build/${common.buildType}/binding`);
77

88
function makeCallback(object, cb) {
9-
binding.makeCallback(object, () => setImmediate(cb));
9+
binding.makeCallback(object, function someMethod() { setImmediate(cb); });
1010
}
1111

1212
let latestWarning = null;
@@ -16,8 +16,14 @@ process.on('warning', (warning) => {
1616

1717
const d = domain.create();
1818

19+
class Resource {
20+
constructor(domain) {
21+
this.domain = domain;
22+
}
23+
}
24+
1925
// When domain is disabled, no warning will be emitted
20-
makeCallback({ domain: d }, common.mustCall(() => {
26+
makeCallback(new Resource(d), common.mustCall(() => {
2127
assert.strictEqual(latestWarning, null);
2228

2329
d.run(common.mustCall(() => {
@@ -26,7 +32,9 @@ makeCallback({ domain: d }, common.mustCall(() => {
2632
assert.strictEqual(latestWarning, null);
2733

2834
// Warning is emitted when domain property is used and domain is enabled
29-
makeCallback({ domain: d }, common.mustCall(() => {
35+
makeCallback(new Resource(d), common.mustCall(() => {
36+
assert.match(latestWarning.message,
37+
/Triggered by calling someMethod on Resource\./);
3038
assert.strictEqual(latestWarning.name, 'DeprecationWarning');
3139
assert.strictEqual(latestWarning.code, 'DEP0097');
3240
}));

0 commit comments

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