This repository was archived by the owner on Dec 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
52 lines (43 loc) · 1.41 KB
/
errors.go
File metadata and controls
52 lines (43 loc) · 1.41 KB
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
package database
import (
"errors"
"strings"
)
var (
// ErrNoSuchEntity is returned from a Get operation when there is not a model
// that matches the query
ErrNoSuchEntity = errors.New("database: no such entity")
// ErrDone is returned from the Next() method of an iterator when all results
// have been read.
ErrDone = errors.New("query has no more results")
// ErrConcurrentTransaction is returned when trying to update a model that has been
// updated in the background by other process. This errors will prevent you from
// potentially overwriting those changes.
ErrConcurrentTransaction = errors.New("database: concurrent transaction")
)
// MultiError stores a list of error when retrieving multiple models and only
// some of them may fail.
type MultiError []error
func (merr MultiError) Error() string {
var msg []string
for _, err := range merr {
if err == nil {
msg = append(msg, "<nil>")
} else {
msg = append(msg, err.Error())
}
}
return strings.Join(msg, "; ")
}
// HasError returns if the multi error really contains any error or all the rows
// have been successfully retrieved. You don't have to check this method most of
// the time because GetMulti, GetAll, etc. will return nil if there is no errors
// instead of an empty MultiErrorto avoid hard to debug bugs.
func (merr MultiError) HasError() bool {
for _, err := range merr {
if err != nil {
return true
}
}
return false
}