-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix error message in async_hooks constructor
There are two minor issues in the AsyncHook constructor, if the object passed in has an after and/or destroy property that are not functions the errors thrown will still be: TypeError [ERR_ASYNC_CALLBACK]: before must be a function This commit updates the code and adds a unit test. PR-URL: #19000 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
- Loading branch information
Showing
2 changed files
with
28 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
// This tests that AsyncHooks throws an error if bad parameters are passed. | ||
|
||
const common = require('../common'); | ||
const async_hooks = require('async_hooks'); | ||
const non_function = 10; | ||
|
||
typeErrorForFunction('init'); | ||
typeErrorForFunction('before'); | ||
typeErrorForFunction('after'); | ||
typeErrorForFunction('destroy'); | ||
typeErrorForFunction('promiseResolve'); | ||
|
||
function typeErrorForFunction(functionName) { | ||
common.expectsError(() => { | ||
async_hooks.createHook({ [functionName]: non_function }); | ||
}, { | ||
code: 'ERR_ASYNC_CALLBACK', | ||
type: TypeError, | ||
message: `hook.${functionName} must be a function` | ||
}); | ||
} |