MCPcopy Index your code
hub / github.com/coder/coder / IsCheckViolation

Function IsCheckViolation

coderd/database/errors.go:66–82  ·  view source on GitHub ↗

IsCheckViolation checks if the error is due to a check violation. If one or more specific check constraints are given as arguments, the error must be caused by one of them. If no constraints are given, this function returns true for any check violation.

(err error, checkConstraints ...CheckConstraint)

Source from the content-addressed store, hash-verified

64// caused by one of them. If no constraints are given, this function returns
65// true for any check violation.
66func IsCheckViolation(err error, checkConstraints ...CheckConstraint) bool {
67 var pqErr *pq.Error
68 if errors.As(err, &pqErr) {
69 if pqErr.Code.Name() == "check_violation" {
70 if len(checkConstraints) == 0 {
71 return true
72 }
73 for _, cc := range checkConstraints {
74 if pqErr.Constraint == string(cc) {
75 return true
76 }
77 }
78 }
79 }
80
81 return false
82}
83
84// IsQueryCanceledError checks if the error is due to a query being canceled.
85func IsQueryCanceledError(err error) bool {

Calls 2

AsMethod · 0.80
NameMethod · 0.65