forked from ThalesGroup/kmip-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
44 lines (35 loc) · 885 Bytes
/
errors.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
package kmip
import (
"errors"
"fmt"
"github.com/ansel1/merry"
"github.com/gemalto/kmip-go/ttlv"
)
func Is(err error, originals ...error) bool {
return merry.Is(err, originals...)
}
func Details(err error) string {
return merry.Details(err)
}
var ErrInvalidTag = errors.New("invalid tag")
type errKey int
const (
errorKeyResultReason errKey = iota
)
func init() {
merry.RegisterDetail("Result Reason", errorKeyResultReason)
}
func WithResultReason(err error, rr ttlv.ResultReason) error {
return merry.WithValue(err, errorKeyResultReason, rr)
}
func GetResultReason(err error) ttlv.ResultReason {
v := merry.Value(err, errorKeyResultReason)
switch t := v.(type) {
case nil:
return ttlv.ResultReason(0)
case ttlv.ResultReason:
return t
default:
panic(fmt.Sprintf("err result reason attribute's value was wrong type, expected ResultReason, got %T", v))
}
}