(cause: unknown)
| 35 | >; |
| 36 | |
| 37 | const isUniqueViolation = (cause: unknown): boolean => { |
| 38 | let current = cause; |
| 39 | for (let i = 0; i < 5; i += 1) { |
| 40 | const err = |
| 41 | current && typeof current === "object" ? (current as Record<string, unknown>) : null; |
| 42 | if (!err) return false; |
| 43 | const code = err["code"]; |
| 44 | // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: database drivers expose unique-violation details on native error messages |
| 45 | const message = err["message"]; |
| 46 | const innerCause = err["cause"]; |
| 47 | if (code === "23505") return true; |
| 48 | if ( |
| 49 | typeof message === "string" && |
| 50 | /unique constraint|duplicate key|violates unique constraint/i.test(message) |
| 51 | ) { |
| 52 | return true; |
| 53 | } |
| 54 | if (!innerCause || innerCause === current) return false; |
| 55 | current = innerCause; |
| 56 | } |
| 57 | return false; |
| 58 | }; |
| 59 | |
| 60 | const causeMessage = (cause: unknown): string | undefined => { |
| 61 | const message = |
no outgoing calls
no test coverage detected