-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
127 lines (113 loc) · 4.54 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package flags
import (
"errors"
"fmt"
)
var (
// ErrParse is a general error used to wrap more specific errors.
ErrParse = errors.New("parse error")
// ErrNotPointerToStruct indicates that a provided data container is not
// a pointer to a struct. Only pointers to structs are valid data containers
// for options.
ErrNotPointerToStruct = errors.New("object must be a pointer to struct or interface")
// ErrNotCommander is returned when an embedded struct is tagged as a command,
// but does not implement even the most simple interface, Commander.
ErrNotCommander = errors.New("provided data does not implement Commander")
// ErrObjectIsNil is returned when the struct/object/pointer is nil.
ErrObjectIsNil = errors.New("object cannot be nil")
// ErrInvalidTag indicates an invalid tag or invalid use of an existing tag.
ErrInvalidTag = errors.New("invalid tag")
// ErrTag indicates an error while parsing flag tags.
ErrTag = errors.New("tag error")
// ErrShortNameTooLong indicates that a short flag name was specified,
// longer than one character.
ErrShortNameTooLong = errors.New("short names can only be 1 character long")
// ErrFlagHandler indicates that the custom handler for a flag has failed.
ErrFlagHandler = errors.New("custom handler for flag failed")
// ErrNotValue indicates that a struct field type does not implement the
// Value interface. This only happens when the said type is a user-defined one.
ErrNotValue = errors.New("invalid field marked as flag")
)
// simple wrapper for errors.
func newError(err error, msg string) error {
return fmt.Errorf("%s: %w", msg, err)
}
// ParserError represents the type of error.
// type ParserError uint
// ORDER IN WHICH THE ERROR CONSTANTS APPEAR MATTERS.
// const (
// // ErrUnknown indicates a generic error.
// ErrUnknown ParserError = iota
//
// // ErrExpectedArgument indicates that an argument was expected.
// ErrExpectedArgument
//
// // ErrUnknownFlag indicates an unknown flag.
// ErrUnknownFlag
//
// // ErrUnknownGroup indicates an unknown group.
// ErrUnknownGroup
//
// // ErrMarshal indicates a marshalling error while converting values.
// ErrMarshal
//
// // ErrHelp indicates that the built-in help was shown (the error
// // contains the help message).
// ErrHelp
//
// // ErrNoArgumentForBool indicates that an argument was given for a
// // boolean flag (which don't not take any arguments).
// ErrNoArgumentForBool
//
// // ErrRequired indicates that a required flag was not provided.
// ErrRequired
//
// // ErrShortNameTooLong indicates that a short flag name was specified,
// // longer than one character.
// // ErrShortNameTooLong
//
// // ErrDuplicatedFlag indicates that a short or long flag has been
// // defined more than once.
// ErrDuplicatedFlag
//
// // ErrTag indicates an error while parsing flag tags.
// // ErrTag
//
// // ErrCommandRequired indicates that a command was required but not
// // specified.
// ErrCommandRequired
//
// // ErrUnknownCommand indicates that an unknown command was specified.
// ErrUnknownCommand
//
// // ErrInvalidChoice indicates an invalid option value which only allows
// // a certain number of choices.
// ErrInvalidChoice
//
// // ErrInvalidTag indicates an invalid tag or invalid use of an existing tag.
// // ErrInvalidTag
// )
// func (e ParserError) String() string {
// errs := [...]string{
// // Public
// "unknown", // ErrUnknown
// "expected argument", // ErrExpectedArgument
// "unknown flag", // ErrUnknownFlag
// "unknown group", // ErrUnknownGroup
// "marshal", // ErrMarshal
// "help", // ErrHelp
// "no argument for bool", // ErrNoArgumentForBool
// "duplicated flag", // ErrDuplicatedFlag
// // "tag", // ErrTag
// "command required", // ErrCommandRequired
// "unknown command", // ErrUnknownCommand
// "invalid choice", // ErrInvalidChoice
// // "invalid tag", // ErrInvalidTag
// }
// if len(errs) > int(e) {
// return "unrecognized error type"
// }
//
// return errs[e]
// }
//