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

Function classifyError

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

Source from the content-addressed store, hash-verified

109}
110
111const classifyError = (
112 cause: unknown,
113 message: string,
114 operation: string
115) => {
116 const props = { cause, message, operation }
117 const errno = mysqlErrnoFromCause(cause)
118 if (errno !== undefined) {
119 if (mysqlConnectionErrorCodes.has(errno)) {
120 return new ConnectionError(props)
121 }
122 if (errno === 1045) {
123 return new AuthenticationError(props)
124 }
125 if (mysqlAuthorizationErrorCodes.has(errno)) {
126 return new AuthorizationError(props)
127 }
128 if (mysqlSyntaxErrorCodes.has(errno)) {
129 return new SqlSyntaxError(props)
130 }
131 if (errno === 1062) {
132 return new UniqueViolation({ ...props, constraint: mysqlDuplicateEntryConstraintFromCause(cause) })
133 }
134 if (mysqlConstraintErrorCodes.has(errno)) {
135 return new ConstraintError(props)
136 }
137 if (errno === 1213) {
138 return new DeadlockError(props)
139 }
140 if (errno === 1205) {
141 return new LockTimeoutError(props)
142 }
143 if (errno === 3024) {
144 return new StatementTimeoutError(props)
145 }
146 }
147 return new UnknownError(props)
148}
149
150/**
151 * 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.65

Tested by

no test coverage detected