@@ -966,21 +966,23 @@ assert.ifError = function ifError(err) {
966966 // This will remove any duplicated frames from the error frames taken
967967 // from within `ifError` and add the original error frames to the newly
968968 // created ones.
969- const tmp2 = StringPrototypeSplit ( origStack , '\n' ) ;
970- ArrayPrototypeShift ( tmp2 ) ;
971- // Filter all frames existing in err.stack.
972- let tmp1 = StringPrototypeSplit ( newErr . stack , '\n' ) ;
973- for ( const errFrame of tmp2 ) {
974- // Find the first occurrence of the frame.
975- const pos = ArrayPrototypeIndexOf ( tmp1 , errFrame ) ;
976- if ( pos !== - 1 ) {
977- // Only keep new frames.
978- tmp1 = ArrayPrototypeSlice ( tmp1 , 0 , pos ) ;
979- break ;
969+ const origStackStart = origStack . indexOf ( '\n at' ) ;
970+ if ( origStackStart !== - 1 ) {
971+ const originalFrames = StringPrototypeSplit ( origStack . slice ( origStackStart + 1 ) , '\n' ) ;
972+ // Filter all frames existing in err.stack.
973+ let newFrames = StringPrototypeSplit ( newErr . stack , '\n' ) ;
974+ for ( const errFrame of originalFrames ) {
975+ // Find the first occurrence of the frame.
976+ const pos = ArrayPrototypeIndexOf ( newFrames , errFrame ) ;
977+ if ( pos !== - 1 ) {
978+ // Only keep new frames.
979+ newFrames = ArrayPrototypeSlice ( newFrames , 0 , pos ) ;
980+ break ;
981+ }
980982 }
983+ newErr . stack =
984+ `${ ArrayPrototypeJoin ( newFrames , '\n' ) } \n${ ArrayPrototypeJoin ( originalFrames , '\n' ) } ` ;
981985 }
982- newErr . stack =
983- `${ ArrayPrototypeJoin ( tmp1 , '\n' ) } \n${ ArrayPrototypeJoin ( tmp2 , '\n' ) } ` ;
984986 }
985987
986988 throw newErr ;
0 commit comments