-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchers.go
More file actions
34 lines (27 loc) · 873 Bytes
/
matchers.go
File metadata and controls
34 lines (27 loc) · 873 Bytes
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
package errors
import "strings"
// HasMessage reports whether any error in err's chain matches msg. It performs a case-insensitive matching.
//
// This is helpful when the error type's in err's chain is unknown and a string matching is preferred.
func HasMessage(err error, msg string) bool {
errs := Flatten(err)
for _, e := range errs {
if strings.EqualFold(e.Msg, msg) {
return true
}
}
return false
}
// ContainsMessage reports whether any error in err's chain contains msg. It performs a case-insensitive matching.
//
// This is helpful when the error type's in err's chain is unknown and a string matching is preferred.
func ContainsMessage(err error, msg string) bool {
errs := Flatten(err)
lowerMsg := strings.ToLower(msg)
for _, e := range errs {
if strings.Contains(strings.ToLower(e.Msg), lowerMsg) {
return true
}
}
return false
}