forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errutil.go
32 lines (28 loc) · 815 Bytes
/
errutil.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
package errutil
import (
"fmt"
"strings"
)
var (
// ErrBreak is an error used to break out of call back based iteration,
// should be swallowed by iteration functions and treated as successful
// iteration.
ErrBreak = fmt.Errorf("BREAK")
)
// IsAlreadyExistError returns true if err is due to trying to create a
// resource that already exists. It uses simple string matching, it's not
// terribly smart.
func IsAlreadyExistError(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), "already exists")
}
// IsNotFoundError returns true if err is due to a resource not being found. It
// uses simple string matching, it's not terribly smart.
func IsNotFoundError(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), "not found")
}