-
Notifications
You must be signed in to change notification settings - Fork 36
/
error.go
64 lines (56 loc) · 1.27 KB
/
error.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
package gorqlite
import (
"errors"
"fmt"
"strings"
)
var _ error = StatementErrors{}
type StatementErrors []error
func joinErrors(errs ...error) error {
if len(errs) == 0 {
return nil
}
var se StatementErrors
for _, err := range errs {
if err == nil {
continue
}
se = append(se, err)
}
if len(se) == 0 {
return nil
}
return se
}
// Error returns a string representation of the statement errors.
func (errs StatementErrors) Error() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("there were %d statement errors", len(errs)))
for _, err := range errs {
sb.WriteString("\n")
sb.WriteString(err.Error())
}
return sb.String()
}
// Unwrap returns the slice of statement errors.
func (errs StatementErrors) Unwrap() []error {
return errs
}
// Is returns true if the current error, or one of the statement errors is equal to the target error.
func (errs StatementErrors) Is(target error) bool {
for _, err := range errs {
if errors.Is(err, target) {
return true
}
}
return false
}
// As returns true if the current error, or one of the statement errors can be assigned to the target error.
func (errs StatementErrors) As(target interface{}) bool {
for _, err := range errs {
if errors.As(err, target) {
return true
}
}
return false
}