MCPcopy
hub / github.com/CodebuffAI/codebuff / getPostgresErrorCode

Function getPostgresErrorCode

packages/internal/src/db/transaction.ts:95–120  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

93}
94
95function getPostgresErrorCode(error: unknown): string | null {
96 if (!error || typeof error !== 'object') {
97 return null
98 }
99
100 let current: unknown = error
101 const seen = new Set<object>()
102 let depth = 0
103
104 while (current && typeof current === 'object' && depth < MAX_ERROR_CAUSE_DEPTH) {
105 if (seen.has(current)) {
106 return null // Circular reference detected
107 }
108 seen.add(current)
109
110 const record = current as Record<string, unknown>
111 if (typeof record.code === 'string' && PG_ERROR_CODE_REGEX.test(record.code)) {
112 return record.code
113 }
114
115 current = record.cause
116 depth += 1
117 }
118
119 return null
120}
121
122/**
123 * Checks if an error is a retryable PostgreSQL error.

Callers 3

Calls

no outgoing calls

Tested by

no test coverage detected