| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0326f0 commit a7dfa43
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,18 @@ const stack = err.stack; | |||
| 39 | 39 | })(); | |
| 40 | 40 | })(); | |
| 41 | 41 | ||
| 42 | + assert.throws( | ||
| 43 | + () => { | ||
| 44 | + const error = new Error(); | ||
| 45 | + error.stack = 'Error: containing weird stack\nYes!\nI am part of a stack.'; | ||
| 46 | + assert.ifError(error); | ||
| 47 | + }, | ||
| 48 | + (error) => { | ||
| 49 | + assert(!error.stack.includes('Yes!')); | ||
| 50 | + return true; | ||
| 51 | + } | ||
| 52 | + ); | ||
| 53 | + | ||
| 42 | 54 | assert.throws( | |
| 43 | 55 | () => assert.ifError(new TypeError()), | |
| 44 | 56 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments