| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2192b5b commit cbb3627
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1243,9 +1243,16 @@ function getStackString(error) { | |||
| 1243 | 1243 | function getStackFrames(ctx, err, stack) { | |
| 1244 | 1244 | const frames = StringPrototypeSplit(stack, '\n'); | |
| 1245 | 1245 | ||
| 1246 | + let cause; | ||
| 1247 | + try { | ||
| 1248 | + ({ cause } = err); | ||
| 1249 | + } catch { | ||
| 1250 | + // If 'cause' is a getter that throws, ignore it. | ||
| 1251 | + } | ||
| 1252 | + | ||
| 1246 | 1253 | // Remove stack frames identical to frames in cause. | |
| 1247 | - if (err.cause && isError(err.cause)) { | ||
| 1248 | - const causeStack = getStackString(err.cause); | ||
| 1254 | + if (cause != null && isError(cause)) { | ||
| 1255 | + const causeStack = getStackString(cause); | ||
| 1249 | 1256 | const causeStackStart = StringPrototypeIndexOf(causeStack, '\n at'); | |
| 1250 | 1257 | if (causeStackStart !== -1) { | |
| 1251 | 1258 | const causeFrames = StringPrototypeSplit(StringPrototypeSlice(causeStack, causeStackStart + 1), '\n'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,3 +46,9 @@ process.nextTick(() => { | |||
| 46 | 46 | console.log(inspect(cause3)); | |
| 47 | 47 | console.log(inspect(error2)); | |
| 48 | 48 | }); | |
| 49 | + | ||
| 50 | + { | ||
| 51 | + const error = new Error('cause that throws'); | ||
| 52 | + Reflect.defineProperty(error, 'cause', { get() { throw new Error(); } }); | ||
| 53 | + console.log(inspect(error)); | ||
| 54 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,16 @@ Error: undefined cause | |||
| 33 | 33 | at * { | |
| 34 | 34 | [cause]: undefined | |
| 35 | 35 | } | |
| 36 | + Error: cause that throws | ||
| 37 | + at * | ||
| 38 | + at * | ||
| 39 | + at * | ||
| 40 | + at * | ||
| 41 | + at * | ||
| 42 | + at * | ||
| 43 | + at * { | ||
| 44 | + [cause]: [Getter] | ||
| 45 | + } | ||
| 36 | 46 | RangeError: New Stack Frames | |
| 37 | 47 | at * | |
| 38 | 48 | *[90m at *[39m { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments