(cause: unknown)
| 531 | } |
| 532 | |
| 533 | const sqliteUniqueConstraintFromCause = (cause: unknown): string => { |
| 534 | if (Predicate.hasProperty(cause, "constraint")) { |
| 535 | return normalizeConstraintIdentifier(cause.constraint) |
| 536 | } |
| 537 | if (!Predicate.hasProperty(cause, "message")) { |
| 538 | return UNKNOWN_CONSTRAINT |
| 539 | } |
| 540 | const message = cause.message |
| 541 | if (typeof message !== "string") { |
| 542 | return UNKNOWN_CONSTRAINT |
| 543 | } |
| 544 | const prefix = "UNIQUE constraint failed:" |
| 545 | const index = message.indexOf(prefix) |
| 546 | return index === -1 ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(message.slice(index + prefix.length)) |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Classifies a native SQLite error cause into a `SqlErrorReason` using its |
no test coverage detected