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

Function classifyError

repos/effect/packages/sql/pg/src/PgClient.ts:910–950  ·  view source on GitHub ↗
(
  cause: unknown,
  message: string,
  operation: string
)

Source from the content-addressed store, hash-verified

908 return undefined
909 }
910 const code = cause.code
911 return typeof code === "string" ? code : undefined
912}
913
914const pgConstraintFromCause = (cause: unknown): string => {
915 if (typeof cause !== "object" || cause === null || !("constraint" in cause)) {
916 return "unknown"
917 }
918 const constraint = cause.constraint
919 if (typeof constraint !== "string") {
920 return "unknown"
921 }
922 const normalized = constraint.trim()
923 return normalized.length === 0 ? "unknown" : normalized
924}
925
926const classifyError = (
927 cause: unknown,
928 message: string,
929 operation: string
930) => {
931 const props = { cause, message, operation }
932 const code = pgCodeFromCause(cause)
933 if (code !== undefined) {
934 if (code.startsWith("08")) {
935 return new ConnectionError(props)
936 }
937 if (code.startsWith("28")) {
938 return new AuthenticationError(props)
939 }
940 if (code === "42501") {
941 return new AuthorizationError(props)
942 }
943 if (code.startsWith("42")) {
944 return new SqlSyntaxError(props)
945 }
946 if (code === "23505") {
947 return new UniqueViolation({ ...props, constraint: pgConstraintFromCause(cause) })
948 }
949 if (code.startsWith("23")) {
950 return new ConstraintError(props)
951 }
952 if (code === "40P01") {
953 return new DeadlockError(props)

Callers 9

makeFunction · 0.70
makeClientFunction · 0.70
onErrorFunction · 0.70
makeConectionFunction · 0.70
PgClient.tsFile · 0.70
runMethod · 0.70
executeRawMethod · 0.70
executeValuesMethod · 0.70
executeStreamMethod · 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…