MCPcopy Index your code
hub / github.com/simstudioai/sim / readPgErrorField

Function readPgErrorField

packages/utils/src/errors.ts:96–122  ·  view source on GitHub ↗
(error: unknown, field: string)

Source from the content-addressed store, hash-verified

94}
95
96function readPgErrorField(error: unknown, field: string): string | undefined {
97 const seen = new Set<unknown>()
98 let current: unknown = error
99
100 while (current !== undefined && current !== null) {
101 if (seen.has(current)) {
102 break
103 }
104 seen.add(current)
105
106 if (typeof current === 'object') {
107 const value = (current as Record<string, unknown>)[field]
108 if (typeof value === 'string') {
109 return value
110 }
111 }
112
113 if (current instanceof Error && current.cause !== undefined) {
114 current = current.cause
115 continue
116 }
117
118 break
119 }
120
121 return undefined
122}

Callers 2

getPostgresErrorCodeFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected