-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
61 lines (52 loc) · 1.58 KB
/
errors.go
File metadata and controls
61 lines (52 loc) · 1.58 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package confire
import (
"errors"
confireErrors "go.rtnl.ai/confire/errors"
)
// Extract a parse error from an error if it is one.
func ParseError(err error) (*confireErrors.ParseError, bool) {
target := &confireErrors.ParseError{}
if ok := errors.As(err, &target); ok {
return target, true
}
return nil, false
}
// Returns true if the underlying error is a parser error.
func IsParseError(err error) bool {
target := &confireErrors.ParseError{}
return errors.As(err, &target)
}
// Extract validation errors from an error if it is one.
func ValidationErrors(err error) (confireErrors.ValidationErrors, bool) {
target := confireErrors.ValidationErrors{}
if ok := errors.As(err, &target); ok {
return target, true
}
return nil, false
}
// Returns true if the underlying error is a validation error.
func IsValidationErrors(err error) bool {
target := confireErrors.ValidationErrors{}
return errors.As(err, &target)
}
// Extract a configuration error from an error if it is one.
func InvalidConfig(err error) (*confireErrors.InvalidConfig, bool) {
target := &confireErrors.InvalidConfig{}
if ok := errors.As(err, &target); ok {
return target, true
}
return nil, false
}
// Returns true if the underlying error is a configuration error.
func IsInvalidConfig(err error) bool {
target := &confireErrors.InvalidConfig{}
return errors.As(err, &target)
}
// Bringing in the errors from the errors package for convenience.
var (
Required = confireErrors.Required
Invalid = confireErrors.Invalid
Parse = confireErrors.Parse
Wrap = confireErrors.Wrap
Join = confireErrors.Join
)