forked from chaisql/chai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
36 lines (30 loc) · 920 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package chai
import (
"github.com/chaisql/chai/internal/database"
errs "github.com/chaisql/chai/internal/errors"
"github.com/cockroachdb/errors"
)
// IsNotFoundError determines if the given error is a NotFoundError.
// NotFoundError is returned when the requested table, index, object or sequence
// doesn't exist.
var IsNotFoundError = errs.IsNotFoundError
// IsAlreadyExistsError determines if the error is returned as a result of
// a conflict when attempting to create a table, an index, an row or a sequence
// with a name that is already used by another resource.
func IsAlreadyExistsError(err error) bool {
if errs.IsAlreadyExistsError(err) {
return true
}
for err != nil {
if cerr, ok := err.(*database.ConstraintViolationError); ok {
switch cerr.Constraint {
case "UNIQUE", "PRIMARY KEY":
return true
default:
return false
}
}
err = errors.Unwrap(err)
}
return false
}