-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
74 lines (56 loc) · 2.54 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package anystore
import (
"errors"
"zombiezen.com/go/sqlite"
"github.com/anyproto/any-store/internal/driver"
)
var (
// ErrDocExists is returned when attempting to insert a document that already exists.
ErrDocExists = errors.New("any-store: document already exists")
// ErrDocNotFound is returned when a document cannot be found by its ID.
ErrDocNotFound = errors.New("any-store: document not found")
// ErrDocWithoutId is returned when a document is provided without a required ID.
ErrDocWithoutId = errors.New("any-store: document missing ID")
// ErrCollectionExists is returned when attempting to create a collection that already exists.
ErrCollectionExists = errors.New("any-store: collection already exists")
// ErrCollectionNotFound is returned when a collection cannot be found.
ErrCollectionNotFound = errors.New("any-store: collection not found")
// ErrIndexExists is returned when attempting to create an index that already exists.
ErrIndexExists = errors.New("any-store: index already exists")
// ErrIndexNotFound is returned when an index cannot be found.
ErrIndexNotFound = errors.New("any-store: index not found")
// ErrTxIsReadOnly is returned when a write operation is attempted in a read-only transaction.
ErrTxIsReadOnly = errors.New("any-store: transaction is read-only")
// ErrTxIsUsed is returned when an operation is attempted on a transaction that has already been committed or rolled back.
ErrTxIsUsed = errors.New("any-store: transaction has already been used")
// ErrTxOtherInstance is returned when an operation is attempted using a transaction from a different database instance.
ErrTxOtherInstance = errors.New("any-store: transaction belongs to another database instance")
// ErrUniqueConstraint is returned when a unique constraint violation occurs.
ErrUniqueConstraint = errors.New("any-store: unique constraint violation")
// ErrIterClosed is returned when operations are attempted on a closed iterator.
ErrIterClosed = errors.New("any-store: iterator is closed")
ErrDBIsClosed = driver.ErrDBIsClosed
ErrDBIsNotOpened = driver.ErrDBIsNotOpened
ErrIncompatibleVersion = driver.ErrIncompatibleVersion
)
func replaceUniqErr(err, replaceTo error) error {
if err == nil {
return nil
}
switch sqlite.ErrCode(err) {
case sqlite.ResultConstraintPrimaryKey,
sqlite.ResultConstraintUnique:
return replaceTo
}
return err
}
func replaceInterruptErr(err error) error {
if err == nil {
return nil
}
switch sqlite.ErrCode(err) {
case sqlite.ResultInterrupt:
return ErrDBIsClosed
}
return err
}