1
1
'use strict' ;
2
2
3
- const errors = require ( 'internal/errors' ) ;
3
+ const {
4
+ ERR_ASYNC_CALLBACK ,
5
+ ERR_INVALID_ARG_TYPE ,
6
+ ERR_INVALID_ASYNC_ID
7
+ } = require ( 'internal/errors' ) . codes ;
4
8
const async_wrap = process . binding ( 'async_wrap' ) ;
5
9
const internal_async_hooks = require ( 'internal/async_hooks' ) ;
6
10
@@ -41,15 +45,15 @@ const {
41
45
class AsyncHook {
42
46
constructor ( { init, before, after, destroy, promiseResolve } ) {
43
47
if ( init !== undefined && typeof init !== 'function' )
44
- throw new errors . TypeError ( ' ERR_ASYNC_CALLBACK' , 'hook.init' ) ;
48
+ throw new ERR_ASYNC_CALLBACK ( 'hook.init' ) ;
45
49
if ( before !== undefined && typeof before !== 'function' )
46
- throw new errors . TypeError ( ' ERR_ASYNC_CALLBACK' , 'hook.before' ) ;
50
+ throw new ERR_ASYNC_CALLBACK ( 'hook.before' ) ;
47
51
if ( after !== undefined && typeof after !== 'function' )
48
- throw new errors . TypeError ( ' ERR_ASYNC_CALLBACK' , 'hook.after' ) ;
52
+ throw new ERR_ASYNC_CALLBACK ( 'hook.after' ) ;
49
53
if ( destroy !== undefined && typeof destroy !== 'function' )
50
- throw new errors . TypeError ( ' ERR_ASYNC_CALLBACK' , 'hook.destroy' ) ;
54
+ throw new ERR_ASYNC_CALLBACK ( 'hook.destroy' ) ;
51
55
if ( promiseResolve !== undefined && typeof promiseResolve !== 'function' )
52
- throw new errors . TypeError ( ' ERR_ASYNC_CALLBACK' , 'hook.promiseResolve' ) ;
56
+ throw new ERR_ASYNC_CALLBACK ( 'hook.promiseResolve' ) ;
53
57
54
58
this [ init_symbol ] = init ;
55
59
this [ before_symbol ] = before ;
@@ -140,7 +144,7 @@ function showEmitBeforeAfterWarning() {
140
144
class AsyncResource {
141
145
constructor ( type , opts = { } ) {
142
146
if ( typeof type !== 'string' )
143
- throw new errors . TypeError ( ' ERR_INVALID_ARG_TYPE' , 'type' , 'string' ) ;
147
+ throw new ERR_INVALID_ARG_TYPE ( 'type' , 'string' ) ;
144
148
145
149
if ( typeof opts === 'number' ) {
146
150
opts = { triggerAsyncId : opts , requireManualDestroy : false } ;
@@ -152,9 +156,7 @@ class AsyncResource {
152
156
// triggerAsyncId.
153
157
const triggerAsyncId = opts . triggerAsyncId ;
154
158
if ( ! Number . isSafeInteger ( triggerAsyncId ) || triggerAsyncId < - 1 ) {
155
- throw new errors . RangeError ( 'ERR_INVALID_ASYNC_ID' ,
156
- 'triggerAsyncId' ,
157
- triggerAsyncId ) ;
159
+ throw new ERR_INVALID_ASYNC_ID ( 'triggerAsyncId' , triggerAsyncId ) ;
158
160
}
159
161
160
162
this [ async_id_symbol ] = newAsyncId ( ) ;
0 commit comments