MCPcopy Create free account
hub / github.com/Effect-TS/effect / sqliteUniqueConstraintFromCause

Function sqliteUniqueConstraintFromCause

packages/effect/src/sql/SqlError.ts:533–547  ·  view source on GitHub ↗
(cause: unknown)

Source from the content-addressed store, hash-verified

531}
532
533const 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

Callers 1

classifySqliteErrorFunction · 0.85

Calls 2

sliceMethod · 0.80

Tested by

no test coverage detected