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

Function queryFailureReason

packages/sql/pg/test/SqlErrorClassification.test.ts:5–17  ·  view source on GitHub ↗
(cause: unknown)

Source from the content-addressed store, hash-verified

3import type * as SqlError from "effect/sql/SqlError"
4
5const queryFailureReason = (cause: unknown) => {
6 const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string"
7 ? cause.code
8 : undefined
9 const constraint = typeof cause === "object" && cause !== null && "constraint" in cause
10 ? cause.constraint
11 : undefined
12 return classifySqlState(code, constraint, {
13 cause,
14 message: "Failed to execute statement",
15 operation: "query"
16 })
17}
18
19const assertUniqueViolation = (reason: SqlError.SqlErrorReason, constraint: string) => {
20 assert.strictEqual(reason._tag, "UniqueViolation")

Calls 1

classifySqlStateFunction · 0.90

Tested by

no test coverage detected