MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / errorFromCause

Function errorFromCause

packages/react/src/api/error-reporting.tsx:83–98  ·  view source on GitHub ↗
(cause: Cause.Cause<unknown>, context: FrontendErrorContext)

Source from the content-addressed store, hash-verified

81};
82
83const 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
100export const toReportableError = (error: unknown, context: FrontendErrorContext): Error => {
101 if (Cause.isCause(error)) return errorFromCause(error, context);

Callers 1

toReportableErrorFunction · 0.85

Calls 4

errorFromValueFunction · 0.85
hasTextFunction · 0.85
describeUnknownFunction · 0.85
withOriginalCauseFunction · 0.85

Tested by

no test coverage detected