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

Function IsUniqueViolation

coderd/database/errors.go:22–38  ·  view source on GitHub ↗

IsUniqueViolation checks if the error is due to a unique violation. If one or more specific unique 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 unique violation.

(err error, uniqueConstraints ...UniqueConstraint)

Source from the content-addressed store, hash-verified

20// the error must be caused by one of them. If no constraints are given,
21// this function returns true for any unique violation.
22func IsUniqueViolation(err error, uniqueConstraints ...UniqueConstraint) bool {
23 var pqErr *pq.Error
24 if errors.As(err, &pqErr) {
25 if pqErr.Code.Name() == "unique_violation" {
26 if len(uniqueConstraints) == 0 {
27 return true
28 }
29 for _, uc := range uniqueConstraints {
30 if pqErr.Constraint == string(uc) {
31 return true
32 }
33 }
34 }
35 }
36
37 return false
38}
39
40// IsForeignKeyViolation checks if the error is due to a foreign key violation.
41// If one or more specific foreign key constraints are given as arguments,

Callers 15

postFileMethod · 0.92
patchTemplateMetaMethod · 0.92
patchWorkspaceMethod · 0.92
postTokenMethod · 0.92
aiProvidersCreateMethod · 0.92
createChatModelConfigMethod · 0.92
updateChatModelConfigMethod · 0.92

Calls 2

AsMethod · 0.80
NameMethod · 0.65

Tested by 1

SetupOrganizationFunction · 0.74