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

Function classifyError

packages/sql/mssql/src/MssqlClient.ts:104–142  ·  view source on GitHub ↗
(
  cause: unknown,
  message: string,
  operation: string,
  fallback: "connection" | "unknown" = "unknown"
)

Source from the content-addressed store, hash-verified

102}
103
104const classifyError = (
105 cause: unknown,
106 message: string,
107 operation: string,
108 fallback: "connection" | "unknown" = "unknown"
109) => {
110 const props = { cause, message, operation }
111 const number = mssqlNumberFromCause(cause)
112 if (number !== undefined) {
113 if (mssqlConnectionErrorCodes.has(number)) {
114 return new ConnectionError(props)
115 }
116 if (mssqlAuthenticationErrorCodes.has(number)) {
117 return new AuthenticationError(props)
118 }
119 if (mssqlAuthorizationErrorCodes.has(number)) {
120 return new AuthorizationError(props)
121 }
122 if (mssqlSyntaxErrorCodes.has(number)) {
123 return new SqlSyntaxError(props)
124 }
125 if (number === 2601 || number === 2627) {
126 return new UniqueViolation({ ...props, constraint: mssqlUniqueViolationConstraintFromCause(number, cause) })
127 }
128 if (mssqlConstraintErrorCodes.has(number)) {
129 return new ConstraintError(props)
130 }
131 if (number === 1205) {
132 return new DeadlockError(props)
133 }
134 if (number === 3960) {
135 return new SerializationError(props)
136 }
137 if (number === 1222) {
138 return new LockTimeoutError(props)
139 }
140 }
141 return fallback === "connection" ? new ConnectionError(props) : new UnknownError(props)
142}
143
144/**
145 * Runtime type identifier used to mark `MssqlClient` values.

Callers 3

makeFunction · 0.70
runFunction · 0.70
runProcedureFunction · 0.70

Calls 3

mssqlNumberFromCauseFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected