1
1
package pqconn
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"slices"
6
7
@@ -31,6 +32,8 @@ func WrapKnownErrors(err error) error {
31
32
return errors .Join (sqldb.ErrUniqueViolation {Constraint : e .Constraint }, err )
32
33
case "23514" :
33
34
return errors .Join (sqldb.ErrCheckViolation {Constraint : e .Constraint }, err )
35
+ case "57014" :
36
+ return errors .Join (context .Canceled , err )
34
37
case "23P01" :
35
38
return errors .Join (sqldb.ErrExclusionViolation {Constraint : e .Constraint }, err )
36
39
case "P0001" :
@@ -42,9 +45,9 @@ func WrapKnownErrors(err error) error {
42
45
43
46
// Class 23 — Integrity Constraint Violation
44
47
45
- func IsIntegrityConstraintViolation (err error ) bool {
48
+ func IsIntegrityConstraintViolationClass (err error ) bool {
46
49
var e * pq.Error
47
- return errors .As (err , & e ) && e .Code == "23000" // integrity_constraint_violation
50
+ return errors .As (err , & e ) && e .Code . Class () == "23"
48
51
}
49
52
50
53
func IsRestrictViolation (err error ) bool {
@@ -78,11 +81,22 @@ func IsExclusionViolation(err error) bool {
78
81
return errors .As (err , & e ) && e .Code == "23P01" // exclusion_violation
79
82
}
80
83
84
+ // Class 57 - Operator Intervention
85
+
86
+ // IsQueryCanceled indicates if the passed error
87
+ // was caused by a user cancellation of a query.
88
+ // The pq error might not unwrap to context.Canceled
89
+ // even when it was caused by a context cancellation.
90
+ func IsQueryCanceled (err error ) bool {
91
+ var e * pq.Error
92
+ return errors .As (err , & e ) && e .Code == "57014"
93
+ }
94
+
81
95
// Class P0 — PL/pgSQL Error
82
96
83
- func IsPLPGSQLError (err error ) bool {
97
+ func IsPLPGSQLErrorClass (err error ) bool {
84
98
var e * pq.Error
85
- return errors .As (err , & e ) && e .Code == "P0000 "
99
+ return errors .As (err , & e ) && e .Code . Class () == "P0 "
86
100
}
87
101
88
102
func IsRaisedException (err error ) bool {
0 commit comments