MCPcopy Create free account
hub / github.com/effect-app/libs / tryToJson

Function tryToJson

packages/effect-app/src/client/errors.ts:6–21  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

4import * as S from "../Schema.ts"
5
6export const tryToJson = (error: unknown) => {
7 try {
8 const errorJson = (error as any).toJSON()
9 return errorJson && typeof errorJson === "object" ? errorJson as Record<string, unknown> : { error }
10 } catch {
11 try {
12 return { error: (error as any).toString() }
13 } catch (err) {
14 try {
15 return { error: `Failed to convert error: ${err}` }
16 } catch {
17 return { error: `Failed to convert error: unknown failure` }
18 }
19 }
20 }
21}
22
23// eslint-disable-next-line unused-imports/no-unused-vars
24// @ts-expect-error type not used

Callers 6

reportErrorFunction · 0.90
reportSentryFunction · 0.90
logErrorFunction · 0.90
reportErrorFunction · 0.90
reportSentryFunction · 0.90
logErrorFunction · 0.90

Calls 2

toJSONMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…