diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-02-26 14:19:52 +0100 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-02-28 07:31:02 +0100 |
commit | f2defcac4dd10f018215e3db530bed1314ce2225 (patch) | |
tree | f5f0d4d5f4719321a65c2b3635e2b0b4fa8d60c8 /test/parallel/test-async-hooks-constructor.js | |
parent | a27e6d7321e129055c08842690533fa5aecfd923 (diff) | |
download | node-new-f2defcac4dd10f018215e3db530bed1314ce2225.tar.gz |
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: https://github.com/nodejs/node/pull/19000
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'test/parallel/test-async-hooks-constructor.js')
-rw-r--r-- | test/parallel/test-async-hooks-constructor.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/parallel/test-async-hooks-constructor.js b/test/parallel/test-async-hooks-constructor.js new file mode 100644 index 0000000000..f2b4df6a9f --- /dev/null +++ b/test/parallel/test-async-hooks-constructor.js @@ -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` + }); +} |