forked from digineo/go-uci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
74 lines (62 loc) · 1.81 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package uci
import "fmt"
// ErrConfigAlreadyLoaded is returned by LoadConfig, if the given Config
// name is already present.
type ErrConfigAlreadyLoaded struct {
Name string
}
func (err ErrConfigAlreadyLoaded) Error() string {
return fmt.Sprintf("%s already loaded", err.Name)
}
// ErrUnknownOptionType is returned when trying to parse an invalid OptionType.
type ErrUnknownOptionType struct {
Type string
}
func (err ErrUnknownOptionType) Error() string {
return fmt.Sprintf("Unknown Option type %s", err.Type)
}
// IsConfigAlreadyLoaded reports, whether err is of type ErrConfigAlredyLoaded.
//
// Deprecated: use errors.Is or errors.As.
func IsConfigAlreadyLoaded(err error) bool {
if err == nil {
return false
}
_, is := err.(*ErrConfigAlreadyLoaded) //nolint:errorlint
return is
}
// ErrSectionTypeMismatch is returned by AddSection if the section-to-add
// already exists with a different type.
type ErrSectionTypeMismatch struct {
Config, Section string // name
ExistingType string
NewType string
}
func (err ErrSectionTypeMismatch) Error() string {
return fmt.Sprintf("type mismatch for %s.%s, got %s, want %s",
err.Config, err.Section, err.ExistingType, err.NewType)
}
// IsSectionTypeMismatch reports, whether err is of type ErrSectionTypeMismatch.
//
// Deprecated: use errors.Is or errors.As.
func IsSectionTypeMismatch(err error) bool {
if err == nil {
return false
}
_, is := err.(*ErrSectionTypeMismatch) //nolint:errorlint
return is
}
type ParseError string
func (err ParseError) Error() string {
return fmt.Sprintf("Parse error: %s", string(err))
}
// IsParseError reports, whether err is of type ParseError.
//
// Deprecated: use errors.Is or errors.As.
func IsParseError(err error) bool {
if err == nil {
return false
}
_, is := err.(*ParseError) //nolint:errorlint
return is
}