File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export default class AggregateError extends Error {
29
29
let message = errors
30
30
. map ( error => {
31
31
// The `stack` property is not standardized, so we can't assume it exists
32
- return typeof error . stack === 'string' ? cleanInternalStack ( cleanStack ( error . stack ) ) : String ( error ) ;
32
+ return typeof error . stack === 'string' && error . stack . length > 0 ? cleanInternalStack ( cleanStack ( error . stack ) ) : String ( error ) ;
33
33
} )
34
34
. join ( '\n' ) ;
35
35
message = '\n' + indentString ( message , 4 ) ;
Original file line number Diff line number Diff line change @@ -51,3 +51,28 @@ test('gracefully handle Error instances without a stack', t => {
51
51
new StacklessError ( 'stackless' )
52
52
] ) ;
53
53
} ) ;
54
+
55
+ test ( 'gracefully handle Error instances with empty stack' , t => {
56
+ class EmptyStackError extends Error {
57
+ constructor ( ...args ) {
58
+ super ( ...args ) ;
59
+ this . name = this . constructor . name ;
60
+ this . stack = '' ;
61
+ }
62
+ }
63
+
64
+ const error = new AggregateError ( [
65
+ new Error ( 'foo' ) ,
66
+ new EmptyStackError ( 'emptystack' )
67
+ ] ) ;
68
+
69
+ console . log ( error ) ;
70
+
71
+ t . regex ( error . message , / E r r o r : f o o \n { 8 } a t / ) ;
72
+ t . regex ( error . message , / E m p t y S t a c k E r r o r : e m p t y s t a c k / ) ;
73
+
74
+ t . deepEqual ( [ ...error . errors ] , [
75
+ new Error ( 'foo' ) ,
76
+ new EmptyStackError ( 'emptystack' )
77
+ ] ) ;
78
+ } ) ;
You can’t perform that action at this time.
0 commit comments