(error: Error & { cause?: Error }, cause: Error)
| 18 | const seenErrors = new WeakSet(); |
| 19 | |
| 20 | function recurse(error: Error & { cause?: Error }, cause: Error): void { |
| 21 | // If we've already seen the error, there is a recursive loop somewhere in the error's |
| 22 | // cause chain. Let's just bail out then to prevent a stack overflow. |
| 23 | if (seenErrors.has(error)) { |
| 24 | return; |
| 25 | } |
| 26 | if (error.cause) { |
| 27 | seenErrors.add(error); |
| 28 | return recurse(error.cause, cause); |
| 29 | } |
| 30 | error.cause = cause; |
| 31 | } |
| 32 | |
| 33 | recurse(error, cause); |
| 34 | } |