GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — domain: improve deprecation warning text for DEP0097 · nodejs/node@4807499

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • domain.js
  • test/addons/make-callback-domain-warning
    • test.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.