File tree 2 files changed +36
-2
lines changed
2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -821,8 +821,11 @@ function hideInternalStackFrames(error) {
821
821
// to make usage of the error in userland and readable-stream easier.
822
822
// It is a regular error with `.code` and `.name`.
823
823
class AbortError extends Error {
824
- constructor ( ) {
825
- super ( 'The operation was aborted' ) ;
824
+ constructor ( message = 'The operation was aborted' , options = undefined ) {
825
+ if ( options !== undefined && typeof options !== 'object' ) {
826
+ throw new codes . ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
827
+ }
828
+ super ( message , options ) ;
826
829
this . code = 'ABORT_ERR' ;
827
830
this . name = 'AbortError' ;
828
831
}
Original file line number Diff line number Diff line change
1
+ // Flags: --expose-internals
2
+ 'use strict' ;
3
+
4
+ require ( '../common' ) ;
5
+ const {
6
+ strictEqual,
7
+ throws,
8
+ } = require ( 'assert' ) ;
9
+ const { AbortError } = require ( 'internal/errors' ) ;
10
+
11
+ {
12
+ const err = new AbortError ( ) ;
13
+ strictEqual ( err . message , 'The operation was aborted' ) ;
14
+ strictEqual ( err . cause , undefined ) ;
15
+ }
16
+
17
+ {
18
+ const cause = new Error ( 'boom' ) ;
19
+ const err = new AbortError ( 'bang' , { cause } ) ;
20
+ strictEqual ( err . message , 'bang' ) ;
21
+ strictEqual ( err . cause , cause ) ;
22
+ }
23
+
24
+ {
25
+ throws ( ( ) => new AbortError ( '' , false ) , {
26
+ code : 'ERR_INVALID_ARG_TYPE'
27
+ } ) ;
28
+ throws ( ( ) => new AbortError ( '' , '' ) , {
29
+ code : 'ERR_INVALID_ARG_TYPE'
30
+ } ) ;
31
+ }
You can’t perform that action at this time.
0 commit comments