@@ -759,17 +759,13 @@ func getSingleComplianceEvent(db *sql.DB, w http.ResponseWriter,
759
759
// as a convenience so that the keys don't need to be explicitly set to interface{} types when using the
760
760
// `getPqErrKeyVals(err, "key1", "val1")...“ syntax.
761
761
func getPqErrKeyVals (err error , additionalKeyVals ... interface {}) []interface {} {
762
- unwrappedErr := err
762
+ var pqErr * pq. Error
763
763
764
- for unwrappedErr != nil {
765
- if pqErr , ok := unwrappedErr .(* pq.Error ); ok { //nolint: errorlint
766
- return append (
767
- []interface {}{"dbMessage" , pqErr .Message , "dbDetail" , pqErr .Detail , "dbCode" , pqErr .Code },
768
- additionalKeyVals ... ,
769
- )
770
- }
771
-
772
- unwrappedErr = errors .Unwrap (unwrappedErr )
764
+ if errors .As (err , & pqErr ) {
765
+ return append (
766
+ []interface {}{"dbMessage" , pqErr .Message , "dbDetail" , pqErr .Detail , "dbCode" , pqErr .Code },
767
+ additionalKeyVals ... ,
768
+ )
773
769
}
774
770
775
771
return additionalKeyVals
@@ -1083,8 +1079,9 @@ func postComplianceEvent(serverContext *ComplianceServerCtx, cfg *rest.Config, w
1083
1079
return
1084
1080
}
1085
1081
1086
- pqErr , ok := err .(* pq.Error ) //nolint:errorlint
1087
- if ok && pqErr .Code == postgresForeignKeyViolationCode {
1082
+ var pqErr * pq.Error
1083
+
1084
+ if errors .As (err , & pqErr ) && pqErr .Code == postgresForeignKeyViolationCode {
1088
1085
// This can only happen if the cache is out of date due to data loss in the database because if the
1089
1086
// database ID is provided, it is validated against the database.
1090
1087
log .Info (
0 commit comments