MCPcopy
hub / github.com/simstudioai/sim / describeError

Function describeError

packages/utils/src/errors.ts:64–94  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

62 * the result as an explicit structured field rather than the raw error.
63 */
64export function describeError(error: unknown): DescribedError {
65 const chain: Error[] = []
66 const seen = new Set<unknown>()
67 let current: unknown = error
68 while (current instanceof Error && !seen.has(current) && chain.length < 10) {
69 seen.add(current)
70 chain.push(current)
71 current = current.cause
72 }
73
74 if (chain.length === 0) {
75 const normalized = toError(error)
76 return { name: normalized.name, message: normalized.message }
77 }
78
79 const deepest = chain[chain.length - 1] as Error & Record<string, unknown>
80 const asString = (value: unknown): string | undefined =>
81 typeof value === 'string' ? value : undefined
82 const code = asString(deepest.code)
83 const errno = asString(deepest.errno)
84 const syscall = asString(deepest.syscall)
85
86 return {
87 name: deepest.name,
88 message: deepest.message,
89 ...(code ? { code } : {}),
90 ...(errno ? { errno } : {}),
91 ...(syscall ? { syscall } : {}),
92 ...(chain.length > 1 ? { causeChain: chain.map((e) => `${e.name}: ${e.message}`) } : {}),
93 }
94}
95
96function readPgErrorField(error: unknown, field: string): string | undefined {
97 const seen = new Set<unknown>()

Callers 11

completeMethod · 0.90
applyScheduleUpdateFunction · 0.90
runWorkflowExecutionFunction · 0.90
executeScheduleJobFunction · 0.90
schedulePartialWriteFunction · 0.90
errors.test.tsFile · 0.85

Calls 4

toErrorFunction · 0.85
asStringFunction · 0.70
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected