(cause: Cause.Cause<unknown>, context: FrontendErrorContext)
| 81 | }; |
| 82 | |
| 83 | const errorFromCause = (cause: Cause.Cause<unknown>, context: FrontendErrorContext): Error => { |
| 84 | // `prettyErrors` is the non-lossy conversion: it renders every reason — |
| 85 | // failures AND defects — as a freshly built `Error` that keeps the original's |
| 86 | // name, message and stack frames. |
| 87 | const [rendered] = Cause.prettyErrors(cause); |
| 88 | if (rendered === undefined) return errorFromValue(Cause.squash(cause), context); |
| 89 | if (!hasText(rendered.message)) { |
| 90 | // A tagged error declared without a `message` field renders with an empty |
| 91 | // one — that is what produced `FrontendHandledError: No error message`. |
| 92 | // The rendered Error is ours, built just above, so filling it in cannot |
| 93 | // mutate a value a call site still holds, and assigning (rather than |
| 94 | // rebuilding) keeps the captured stack frames intact. |
| 95 | rendered.message = describeUnknown(Cause.squash(cause), context); |
| 96 | } |
| 97 | return withOriginalCause(rendered, cause); |
| 98 | }; |
| 99 | |
| 100 | export const toReportableError = (error: unknown, context: FrontendErrorContext): Error => { |
| 101 | if (Cause.isCause(error)) return errorFromCause(error, context); |
no test coverage detected