(error: unknown, field: string)
| 94 | } |
| 95 | |
| 96 | function 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 | } |
no test coverage detected