-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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.
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 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,35 @@ | ||
'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; | ||
|
||
common.expectsError(() => { | ||
async_hooks.createHook({ init: non_function }); | ||
}, typeErrorForFunction('init')); | ||
|
||
common.expectsError(() => { | ||
async_hooks.createHook({ before: non_function }); | ||
}, typeErrorForFunction('before')); | ||
|
||
common.expectsError(() => { | ||
async_hooks.createHook({ after: non_function }); | ||
}, typeErrorForFunction('after')); | ||
|
||
common.expectsError(() => { | ||
async_hooks.createHook({ destroy: non_function }); | ||
}, typeErrorForFunction('destroy')); | ||
|
||
common.expectsError(() => { | ||
async_hooks.createHook({ promiseResolve: non_function }); | ||
}, typeErrorForFunction('promiseResolve')); | ||
|
||
function typeErrorForFunction(functionName) { | ||
return { | ||
code: 'ERR_ASYNC_CALLBACK', | ||
type: TypeError, | ||
message: `${functionName} must be a function`, | ||
}; | ||
} |