Commit 111340d
committed
Add pqerror package
Add a pqerror package with a list of error codes. Typical usage might be
something like:
pqErr, ok := errors.AsType[*pq.Error](err)
if ok && pqErr == pqerror.UniqueViolation {
return fmt.Errorf("user already exists")
}
To make this a bit more convenient, it also adds a pqerror.As()
function:
pqErr := pqerror.As(err, pqerror.UniqueViolation)
if pqErr != nil {
log.Fatalf("email %q already exsts", email)
}
if err != nil {
return err
}
This also moves most of the error stuff to the pqerror package, with
type aliases in the pq package so it won't break anything. Has to export
Error.Query to make this work, which is okay. Keep most of the tests in
the main pq package for now, to ensure this works.
Fixes 4921 parent f3ef532 commit 111340d
File tree
12 files changed
+1185
-565
lines changed- pqerror
12 files changed
+1185
-565
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
11 | 27 | | |
12 | 28 | | |
13 | 29 | | |
| |||
23 | 39 | | |
24 | 40 | | |
25 | 41 | | |
| 42 | + | |
26 | 43 | | |
27 | 44 | | |
28 | 45 | | |
| |||
134 | 151 | | |
135 | 152 | | |
136 | 153 | | |
| 154 | + | |
| 155 | + | |
137 | 156 | | |
138 | 157 | | |
139 | 158 | | |
| |||
159 | 178 | | |
160 | 179 | | |
161 | 180 | | |
| 181 | + | |
162 | 182 | | |
163 | 183 | | |
164 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 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 | 14 | | |
58 | 15 | | |
59 | 16 | | |
| |||
0 commit comments