MCPcopy Create free account
hub / github.com/avitorio/outstatic / stringifyError

Function stringifyError

packages/outstatic/src/utils/errors/stringify-error.ts:5–31  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

3 * It handles circular references and common error properties.
4 */
5export function stringifyError(error: unknown): string {
6 const cache = new Set()
7 const replacer = (_key: string, value: any) => {
8 if (typeof value === 'object' && value !== null) {
9 if (cache.has(value)) {
10 return '[Circular]'
11 }
12 cache.add(value)
13 }
14 if (value instanceof Error) {
15 const errorObj: any = {}
16 Object.getOwnPropertyNames(value).forEach((prop) => {
17 errorObj[prop] = (value as any)[prop]
18 })
19 return errorObj
20 }
21 return value
22 }
23
24 try {
25 return JSON.stringify(error, replacer, 2)
26 } catch {
27 return String(error)
28 } finally {
29 cache.clear()
30 }
31}

Callers 8

onSubmitFunction · 0.90
handleSaveParentFunction · 0.90
AISelectorFunction · 0.90
BaseCommandListFunction · 0.90
useTipTapFunction · 0.90
handleSubmitFunction · 0.90
query-client.tsFile · 0.90
useCollectionsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected