(error: Error)
| 479 | }; |
| 480 | |
| 481 | function createMessageAndCause(error: Error) { |
| 482 | if (error.cause) { |
| 483 | const seen = new WeakSet(); |
| 484 | return JSON.stringify(buildSerializeError(error), (_, value) => { |
| 485 | if (isObject(value)) { |
| 486 | if (seen.has(value)) return; |
| 487 | seen.add(value); // stop circular references |
| 488 | } |
| 489 | if (typeof value === 'bigint' || value === undefined) { |
| 490 | return String(value); |
| 491 | } |
| 492 | return value; |
| 493 | }); |
| 494 | } |
| 495 | |
| 496 | return error.message; |
| 497 | } |
| 498 | |
| 499 | function buildSerializeError(error: {[key: string]: any}) { |
| 500 | if (!isObject(error)) { |
no test coverage detected