(error: unknown, context: FrontendErrorContext)
| 98 | }; |
| 99 | |
| 100 | export const toReportableError = (error: unknown, context: FrontendErrorContext): Error => { |
| 101 | if (Cause.isCause(error)) return errorFromCause(error, context); |
| 102 | // oxlint-disable-next-line executor/no-instanceof-error -- boundary: the report is already whatever a call site threw; deciding whether the transport can consume it as-is is this adapter's whole job |
| 103 | if (error instanceof Error) { |
| 104 | // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: narrowed to Error above; an empty message is exactly the case being repaired |
| 105 | if (hasText(error.message)) return error; |
| 106 | // Never mutate an Error a call site owns: rebuild it, carrying the stack. |
| 107 | // oxlint-disable-next-line executor/no-error-constructor -- boundary: a crash-reporting transport only understands built-in Errors |
| 108 | const titled = new Error(describeUnknown(error, context)); |
| 109 | titled.name = error.name; |
| 110 | if (typeof error.stack === "string") titled.stack = error.stack; |
| 111 | return withOriginalCause(titled, error); |
| 112 | } |
| 113 | return errorFromValue(error, context); |
| 114 | }; |
| 115 | |
| 116 | /** Wraps a reporter so it can only ever be handed a titled `Error`. */ |
| 117 | const normalizing = |
no test coverage detected