MCPcopy Index your code
hub / github.com/anomalyco/opencode / errorData

Function errorData

packages/tui/src/util/error.ts:147–182  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

145}
146
147export function errorData(error: unknown) {
148 if (error instanceof Error) {
149 return {
150 type: error.name,
151 message: errorMessage(error),
152 stack: error.stack,
153 cause: error.cause === undefined ? undefined : errorFormat(error.cause),
154 formatted: errorFormat(error),
155 }
156 }
157
158 if (!isRecord(error)) {
159 return {
160 type: typeof error,
161 message: errorMessage(error),
162 formatted: errorFormat(error),
163 }
164 }
165
166 const data = Object.getOwnPropertyNames(error).reduce<Record<string, unknown>>((acc, key) => {
167 const value = error[key]
168 if (value === undefined) return acc
169 if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
170 acc[key] = value
171 return acc
172 }
173 // oxlint-disable-next-line no-base-to-string -- intentional coercion of arbitrary error properties
174 acc[key] = value instanceof Error ? value.message : String(value)
175 return acc
176 }, {})
177
178 if (typeof data.message !== "string") data.message = errorMessage(error)
179 if (typeof data.type !== "string") data.type = error.constructor?.name
180 data.formatted = errorFormat(error)
181 return data
182}

Callers 4

error.test.tsFile · 0.90
runInWorkspaceFunction · 0.90
workspace.tsFile · 0.90
failFunction · 0.90

Calls 3

isRecordFunction · 0.90
errorFormatFunction · 0.85
errorMessageFunction · 0.70

Tested by

no test coverage detected