-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
116 lines (102 loc) · 2.83 KB
/
errors.ts
File metadata and controls
116 lines (102 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { AbortError, ClientError, TimeoutError } from "@probitas/client";
/**
* SQL-specific error kinds.
*/
export type SqlErrorKind =
| "query"
| "constraint"
| "deadlock"
| "connection"
| "unknown";
/**
* Options for SqlError constructor.
*/
export interface SqlErrorOptions extends ErrorOptions {
/** SQL State code (e.g., "23505" for unique violation) */
readonly sqlState?: string;
}
/**
* Base error class for SQL-specific errors.
* Extends ClientError with SQL-specific properties.
*/
export class SqlError extends ClientError {
override readonly name: string = "SqlError";
override readonly kind: SqlErrorKind;
readonly sqlState: string | null;
constructor(
message: string,
kind: SqlErrorKind,
options?: SqlErrorOptions,
) {
super(message, kind, options);
this.kind = kind;
this.sqlState = options?.sqlState ?? null;
}
}
/**
* Error thrown when a SQL query has syntax errors.
*/
export class QuerySyntaxError extends SqlError {
override readonly name = "QuerySyntaxError";
override readonly kind = "query" as const;
constructor(message: string, options?: SqlErrorOptions) {
super(message, "query", options);
}
}
/**
* Error thrown when a constraint violation occurs.
*/
export class ConstraintError extends SqlError {
override readonly name = "ConstraintError";
override readonly kind = "constraint" as const;
readonly constraint: string;
constructor(message: string, constraint: string, options?: SqlErrorOptions) {
super(message, "constraint", options);
this.constraint = constraint;
}
}
/**
* Error thrown when a deadlock is detected.
*/
export class DeadlockError extends SqlError {
override readonly name = "DeadlockError";
override readonly kind = "deadlock" as const;
constructor(message: string, options?: SqlErrorOptions) {
super(message, "deadlock", options);
}
}
/**
* Error thrown when a connection or network-level error occurs.
*
* This includes:
* - Connection refused (server not running)
* - Authentication failure
* - Connection timeout
* - Pool exhaustion
* - TLS handshake failure
* - DNS resolution failure
*/
export class SqlConnectionError extends SqlError {
override readonly name = "SqlConnectionError";
override readonly kind = "connection" as const;
constructor(message: string, options?: SqlErrorOptions) {
super(message, "connection", options);
}
}
/**
* Error types that indicate an operation was processed by the server.
* These errors occur after the query reaches the SQL server.
*/
export type SqlOperationError =
| QuerySyntaxError
| ConstraintError
| DeadlockError
| SqlError;
/**
* Error types that indicate the operation was not processed.
* These are errors that occur before the query reaches the SQL server.
*/
export type SqlFailureError =
| SqlConnectionError
| AbortError
| TimeoutError;