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

Function errorFromCause

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

Source from the content-addressed store, hash-verified

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