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

Function classifyError

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

Source from the content-addressed store, hash-verified

497}
498
499const classifyError = (
500 cause: unknown,
501 message: string,
502 operation: string
503) => {
504 const props = { cause, message, operation }
505 const code = pgCodeFromCause(cause)
506 if (code !== undefined) {
507 if (code.startsWith("08")) {
508 return new ConnectionError(props)
509 }
510 if (code.startsWith("28")) {
511 return new AuthenticationError(props)
512 }
513 if (code === "42501") {
514 return new AuthorizationError(props)
515 }
516 if (code.startsWith("42")) {
517 return new SqlSyntaxError(props)
518 }
519 if (code === "23505") {
520 return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) })
521 }
522 if (code.startsWith("23")) {
523 return new ConstraintError(props)
524 }
525 if (code === "40P01") {
526 return new DeadlockError(props)
527 }
528 if (code === "40001") {
529 return new SerializationError(props)
530 }
531 if (code === "55P03") {
532 return new LockTimeoutError(props)
533 }
534 if (code === "57014") {
535 return new StatementTimeoutError(props)
536 }
537 }
538 return new UnknownError(props)
539}

Callers 6

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

Calls 2

pgCodeFromCauseFunction · 0.85
pgConstraintFromCauseFunction · 0.85

Tested by

no test coverage detected