Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
60c81c0
v8: add new to the throw statement
BridgeAR Jun 21, 2017
f56a4ba
process: Send signal name to signal handlers
robertrossmann Sep 25, 2017
08ccba7
doc: `readable.push(undefined)` in non-object mode
Jan 21, 2018
88adf76
doc: add process.debugPort to doc/api/process.md
flickz Feb 11, 2018
632f277
doc: make the background section concise and improve its formality
Feb 22, 2018
6456de8
src: fix error message in async_hooks constructor
danbev Feb 26, 2018
ac34737
http: prevent aborted event when already completed
billywhizz Feb 17, 2018
33cd733
http: prevent aborted event when already completed
billywhizz Feb 17, 2018
b80c59b
test: refactor test after review
billywhizz Feb 27, 2018
eb03707
test: specify 'dir' for directory symlinks
kfarnung Feb 27, 2018
2320afd
doc: add RegExp Unicode Property Escapes to intl
vsemozhetbyt Feb 28, 2018
3f0973f
doc: Readable unpipe on Writable error event
GeorgeSapkin Feb 8, 2018
aaa6fe5
doc: update list of re-exported symbols
richardlau Feb 26, 2018
8f6b0bd
doc: add URL.format() example
zeke Feb 20, 2018
2552af9
doc: add simple example to rename function
punteek Feb 16, 2018
472874d
doc: remove tentativeness in pull-requests.md
Trott Mar 4, 2018
d661a63
doc: remove subsystem from pull request template
Trott Mar 4, 2018
7f7e993
test: move require http2 to after crypto check
danbev Mar 3, 2018
85d8d22
src: #include <stdio.h>" to iculslocs
srl295 Mar 5, 2018
2ae1048
perf_hooks: fix timing
TimothyGu Feb 25, 2018
2578cdb
test: add more information to assert.strictEqual
ryzokuken Mar 6, 2018
2bb3600
doc: make suggestion more direct in stream.md
Trott Mar 4, 2018
d875750
test: skip postmortem metadata test when nm fails
joyeecheung Mar 3, 2018
5ff1828
doc: add inspector usage example
ofrobots Mar 6, 2018
b7ae752
doc: remove warning against readable/readable.read
Trott Mar 7, 2018
468a289
crypto: use bool over int consistently
tniessen Mar 8, 2018
b3e4775
test: refactor http-https-default-ports
ken23421 Mar 4, 2018
6539227
test: address unreliable test-performance
Trott Mar 8, 2018
e39c12a
test: do not check text for engine-generated error
Trott Mar 8, 2018
ac6f9d5
doc: add warning to assert.doesNotThrow()
BridgeAR Feb 10, 2018
8c206d7
repl: better handling of recoverable errors
princejwesley Feb 21, 2018
cf5c370
test: Remove unnecessary asserion messages in test-crypto-hash.js
pgrzesik Feb 25, 2018
e4accb6
test: fix test-abort-backtrace in shared lib build
yhwang Mar 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <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>
  • Loading branch information
danbev authored and jasnell committed Aug 17, 2018
commit 6456de8b948030ca4db5d74744a7fdaab7b83d60
10 changes: 5 additions & 5 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ const {
class AsyncHook {
constructor({ init, before, after, destroy, promiseResolve }) {
if (init !== undefined && typeof init !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'init');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.init');
if (before !== undefined && typeof before !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.before');
if (after !== undefined && typeof after !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.after');
if (destroy !== undefined && typeof destroy !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.destroy');
if (promiseResolve !== undefined && typeof promiseResolve !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'promiseResolve');
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.promiseResolve');

this[init_symbol] = init;
this[before_symbol] = before;
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-async-hooks-constructor.js
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`
});
}