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

Function classifyError

repos/effect/packages/sql/mysql2/src/MysqlClient.ts:98–135  ·  view source on GitHub ↗
(
  cause: unknown,
  message: string,
  operation: string
)

Source from the content-addressed store, hash-verified

96}
97
98const classifyError = (
99 cause: unknown,
100 message: string,
101 operation: string
102) => {
103 const props = { cause, message, operation }
104 const errno = mysqlErrnoFromCause(cause)
105 if (errno !== undefined) {
106 if (mysqlConnectionErrorCodes.has(errno)) {
107 return new ConnectionError(props)
108 }
109 if (errno === 1045) {
110 return new AuthenticationError(props)
111 }
112 if (mysqlAuthorizationErrorCodes.has(errno)) {
113 return new AuthorizationError(props)
114 }
115 if (mysqlSyntaxErrorCodes.has(errno)) {
116 return new SqlSyntaxError(props)
117 }
118 if (errno === 1062) {
119 return new UniqueViolation({ ...props, constraint: mysqlDuplicateEntryConstraintFromCause(cause) })
120 }
121 if (mysqlConstraintErrorCodes.has(errno)) {
122 return new ConstraintError(props)
123 }
124 if (errno === 1213) {
125 return new DeadlockError(props)
126 }
127 if (errno === 1205) {
128 return new LockTimeoutError(props)
129 }
130 if (errno === 3024) {
131 return new StatementTimeoutError(props)
132 }
133 }
134 return new UnknownError(props)
135}
136
137/**
138 * Runtime type identifier used to mark `MysqlClient` values.

Callers 3

runRawMethod · 0.70
makeFunction · 0.70
queryStreamFunction · 0.70

Calls 3

mysqlErrnoFromCauseFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…