@@ -16,13 +16,14 @@ func contains(xs []string, x string) bool {
1616 return false
1717}
1818
19+ type sqlState interface {
20+ SQLState () string
21+ }
22+
1923// IsErrorCode checks is error has given code
2024func IsErrorCode (err error , code string ) bool {
21- var pqErr * pq.Error
22- if errors .As (err , & pqErr ) && string (pqErr .Code ) == code {
23- return true
24- }
25- return false
25+ sErr , ok := err .(sqlState )
26+ return ok && sErr .SQLState () == code
2627}
2728
2829// IsErrorClass checks is error has given class
@@ -52,7 +53,7 @@ func IsInvalidTextRepresentation(err error) bool {
5253 return IsErrorCode (err , "22P02" )
5354}
5455
55- // IsCharacterNotInRepertoire checks is error an character_not_in_repertoire
56+ // IsCharacterNotInRepertoire checks is error a character_not_in_repertoire
5657func IsCharacterNotInRepertoire (err error ) bool {
5758 return IsErrorCode (err , "22021" )
5859}
@@ -75,7 +76,7 @@ func IsQueryCanceled(err error) bool {
7576 return IsErrorCode (err , "57014" )
7677}
7778
78- // IsSerializationFailure checks is error an serialization_failure error
79+ // IsSerializationFailure checks is error a serialization_failure error
7980// (pq: could not serialize access due to read/write dependencies among transactions)
8081func IsSerializationFailure (err error ) bool {
8182 return IsErrorCode (err , "40001" )
0 commit comments