Skip to content

Commit

Permalink
fixup! util: runtime deprecate promisify-ing a function returning a…
Browse files Browse the repository at this point in the history
… `Promise`
  • Loading branch information
aduh95 committed Sep 16, 2023
1 parent 2fb3d51 commit f9726f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ function promisify(original) {
}
});
if (isPromise(ReflectApply(original, this, args))) {
process.emitWarning('Calling promisify on a function that returns a Promise is likely a mistake.');
process.emitWarning('Calling promisify on a function that returns a Promise is likely a mistake.',
'DeprecationWarning', 'DEP0174');
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions test/parallel/test-util-promisify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ const { customPromisifyArgs } = require('internal/util');
process.off('warning', warningHandler);
}

common.expectWarning('Warning', 'Calling promisify on a function that returns a Promise is likely a mistake.');
common.expectWarning(
'DeprecationWarning',
'Calling promisify on a function that returns a Promise is likely a mistake.',
'DEP0174');
promisify(async (callback) => { callback(); })().then(common.mustCall(() => {
common.expectWarning('Warning', 'Calling promisify on a function that returns a Promise is likely a mistake.');
// We must add the second `expectWarning` call in the `.then` handler, when
// the first warning has already been triggered.
common.expectWarning(
'DeprecationWarning',
'Calling promisify on a function that returns a Promise is likely a mistake.',
'DEP0174');
promisify(async () => {})().then(common.mustNotCall());
}));

Expand Down

0 comments on commit f9726f9

Please sign in to comment.