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

Function classifyError

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 classifyError = (
474 cause: unknown,
475 message: string,
476 operation: string
477) => {
478 const props = { cause, message, operation }
479 const code = pgCodeFromCause(cause)
480 if (code !== undefined) {
481 if (code.startsWith("08")) {
482 return new ConnectionError(props)
483 }
484 if (code.startsWith("28")) {
485 return new AuthenticationError(props)
486 }
487 if (code === "42501") {
488 return new AuthorizationError(props)
489 }
490 if (code.startsWith("42")) {
491 return new SqlSyntaxError(props)
492 }
493 if (code === "23505") {
494 return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) })
495 }
496 if (code.startsWith("23")) {
497 return new ConstraintError(props)
498 }
499 if (code === "40P01") {
500 return new DeadlockError(props)
501 }
502 if (code === "40001") {
503 return new SerializationError(props)
504 }
505 if (code === "55P03") {
506 return new LockTimeoutError(props)
507 }
508 if (code === "57014") {
509 return new StatementTimeoutError(props)
510 }
511 }
512 return new UnknownError(props)
513}

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