-
Notifications
You must be signed in to change notification settings - Fork 0
/
unknown.go
43 lines (34 loc) · 1.06 KB
/
unknown.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
package zerrors
import (
"errors"
"fmt"
"github.com/samber/oops"
)
const ErrUnknown = "unknown"
func ThrowUnknown(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return oops.Code(ErrUnknown).Errorf(message)
}
func ThrowUnknownr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return oops.Code(ErrUnknown).Errorf(message)
}
func Unknown(message string, KVs ...interface{}) error {
return oops.Code(ErrUnknown).With(KVs...).Errorf(message)
}
func Unknownf(format string, a ...interface{}) error {
return oops.Code(ErrUnknown).Errorf(format, a...)
}
func UnknownBuilder() oops.OopsErrorBuilder {
return oops.Code(ErrUnknown)
}
func ToUnknown(parent error, format string, a ...interface{}) error {
return oops.Code(ErrUnknown).Wrapf(parent, format, a...)
}
func IsUnknown(err error) bool {
var possibleError oops.OopsError
if errors.As(err, &possibleError) {
return possibleError.Code() == ErrUnknown
}
return false
}