-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
61 lines (51 loc) · 1.7 KB
/
errors.go
File metadata and controls
61 lines (51 loc) · 1.7 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 cli
import (
"errors"
"fmt"
)
//ExitStatusError allows wrapping together an exit status with an error providing
//that exit code.
type ExitStatusError struct {
//Code is the desired exit status.
Code int
//Err is the wrapped error.
Err error
}
//Error is the error implementation for e.
//It returns e.Err.Error()
func (e *ExitStatusError) Error() string {
return e.Err.Error()
}
//ErrInvalidParameters is a generic error for invalid parameters being set.
//Note that this error message will not be printed to output, it is simply a sentinel
//value.
var ErrInvalidParameters = errors.New("invalid parameters")
//RequiredParameterNotSetError is an error that denotes a parameter was not supplied
//in the arguments but is required to be present.
//If Formatted is not empty, then it is used in Error(). Otherwise, Name is used.
//It is up to client code to set Formatted if that output is desired.
type RequiredParameterNotSetError struct {
//Name is the name of the Parameter.
Name string
//Many is the Many option of the Parameter.
Many bool
//Formatted may be provided to override output of Error().
Formatted string
}
//Error provides the error implementation.
//It returns fmt.Sprintf("required %s %s not set", ParameterName, <value>) where
//<value> is e.Formatted if not empty or e.Name otherwise.
func (e *RequiredParameterNotSetError) Error() string {
value := e.Name
if len(e.Formatted) != 0 {
value = e.Formatted
}
return fmt.Sprintf(
"required %s %s not set",
ParameterName,
value,
)
}
//ErrTooManyParameters is an error value that clients can use to signal that
//too many parameters were provided to a ParameterSetter.
var ErrTooManyParameters = fmt.Errorf("too many parameters")