-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
41 lines (34 loc) · 890 Bytes
/
error.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
package flargs
import "fmt"
type ExitCode uint8
const (
ExitCodeSuccess ExitCode = iota
ExitCodeGenericError
ExitCodeMisuseOfBuiltIns
ExitCodeCannotExecute = iota + 123
ExitCodeCommandNotFound // Command not found
ExitCodeInvalidArgumentToExit
ExitCodeFatalErrorSignal1
ExitCodeFatalErrorSignal2 // Ctrl-C was pressed
ExitCodeFatalErrorSignal3
ExitCodeFatalErrorSignal4
ExitCodeFatalErrorSignal5
ExitCodeFatalErrorSignal6
ExitCodeFatalErrorSignal7
ExitCodeFatalErrorSignal8
ExitCodeFatalErrorSignal9
)
func (ec ExitCode) Error() string {
return fmt.Sprintf("exit code: %d", ec)
}
type FlargError struct {
ExitCode
UnderlyingError error
}
func (fe *FlargError) Error() string {
return fmt.Sprintf("flargs error: %s", fe.UnderlyingError)
}
func NewFlargError(exitcode ExitCode, underlying error) *FlargError {
fe := &FlargError{exitcode, underlying}
return fe
}