@@ -966,21 +966,27 @@ assert.ifError = function ifError(err) {
966
966
// This will remove any duplicated frames from the error frames taken
967
967
// from within `ifError` and add the original error frames to the newly
968
968
// 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 (
972
+ origStack . slice ( origStackStart + 1 ) ,
973
+ '\n'
974
+ ) ;
975
+ // Filter all frames existing in err.stack.
976
+ let newFrames = StringPrototypeSplit ( newErr . stack , '\n' ) ;
977
+ for ( const errFrame of originalFrames ) {
978
+ // Find the first occurrence of the frame.
979
+ const pos = ArrayPrototypeIndexOf ( newFrames , errFrame ) ;
980
+ if ( pos !== - 1 ) {
981
+ // Only keep new frames.
982
+ newFrames = ArrayPrototypeSlice ( newFrames , 0 , pos ) ;
983
+ break ;
984
+ }
980
985
}
986
+ const stackStart = ArrayPrototypeJoin ( newFrames , '\n' ) ;
987
+ const stackEnd = ArrayPrototypeJoin ( originalFrames , '\n' ) ;
988
+ newErr . stack = `${ stackStart } \n${ stackEnd } ` ;
981
989
}
982
- newErr . stack =
983
- `${ ArrayPrototypeJoin ( tmp1 , '\n' ) } \n${ ArrayPrototypeJoin ( tmp2 , '\n' ) } ` ;
984
990
}
985
991
986
992
throw newErr ;
0 commit comments