forked from chaisql/chai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
36 lines (30 loc) · 929 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 genji
import (
"github.com/cockroachdb/errors"
"github.com/genjidb/genji/internal/database"
errs "github.com/genjidb/genji/internal/errors"
)
// IsNotFoundError determines if the given error is a NotFoundError.
// NotFoundError is returned when the requested table, index, document 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, a document 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
}