-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patherrors.go
44 lines (34 loc) · 1022 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 pail
import (
"fmt"
"github.com/pkg/errors"
)
type keyNotFoundError struct {
msg string
}
func (e *keyNotFoundError) Error() string { return e.msg }
// NewKeyNotFoundError creates a new error object to represent a key not found
// error.
func NewKeyNotFoundError(msg string) error { return &keyNotFoundError{msg: msg} }
// NewKeyNotFoundErrorf creates a new error object to represent a key not found
// error with a formatted message.
func NewKeyNotFoundErrorf(msg string, args ...interface{}) error {
return NewKeyNotFoundError(fmt.Sprintf(msg, args...))
}
// MakeKeyNotFoundError constructs a key not found error from an existing error
// of any type.
func MakeKeyNotFoundError(err error) error {
if err == nil {
return nil
}
return NewKeyNotFoundError(err.Error())
}
// IsKeyNotFoundError checks an error object to see if it is a key not found
// error.
func IsKeyNotFoundError(err error) bool {
if err == nil {
return false
}
_, ok := errors.Cause(err).(*keyNotFoundError)
return ok
}