MCPcopy Create free account
hub / github.com/effect-app/libs / classifyError

Function classifyError

repos/effect/packages/sql/pglite/src/PgliteClient.ts:473–513  ·  view source on GitHub ↗
(
  cause: unknown,
  message: string,
  operation: string
)

Source from the content-addressed store, hash-verified

471}
472
473const pgConstraintFromCause = (cause: unknown): string => {
474 if (typeof cause !== "object" || cause === null || !("constraint" in cause)) {
475 return "unknown"
476 }
477 const constraint = cause.constraint
478 if (typeof constraint !== "string") {
479 return "unknown"
480 }
481 const normalized = constraint.trim()
482 return normalized.length === 0 ? "unknown" : normalized
483}
484
485const classifyError = (
486 cause: unknown,
487 message: string,
488 operation: string
489) => {
490 const props = { cause, message, operation }
491 const code = pgCodeFromCause(cause)
492 if (code !== undefined) {
493 if (code.startsWith("08")) {
494 return new ConnectionError(props)
495 }
496 if (code.startsWith("28")) {
497 return new AuthenticationError(props)
498 }
499 if (code === "42501") {
500 return new AuthorizationError(props)
501 }
502 if (code.startsWith("42")) {
503 return new SqlSyntaxError(props)
504 }
505 if (code === "23505") {
506 return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) })
507 }
508 if (code.startsWith("23")) {
509 return new ConstraintError(props)
510 }
511 if (code === "40P01") {
512 return new DeadlockError(props)
513 }
514 if (code === "40001") {
515 return new SerializationError(props)
516 }

Callers 6

makeFunction · 0.70
fromClientFunction · 0.70
runMethod · 0.70
executeRawMethod · 0.70
executeValuesMethod · 0.70

Calls 2

pgCodeFromCauseFunction · 0.70
pgConstraintFromCauseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…