-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
54 lines (48 loc) · 1.14 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
package main
// errorList is a small struct of exit errors
type exitError struct {
ID int
Exit int
Description string
}
var (
errContinue = -2 // no error, do nothing
errUnknown = -1
errOK = 0 // no error
errNoParams = 1
errParh = 2
errFileTypes = 3
errScript = 4
errStorage = 5
exitErrors = map[int]exitError{
errContinue: {errContinue, 0, ""},
errUnknown: {errUnknown, 1, "unknown error."},
errOK: {errOK, 0, "Exited, bye."},
errNoParams: {errNoParams, 1, "Unspecified params: "},
errParh: {errParh, 1, "error in path: "},
errFileTypes: {errFileTypes, 1, "error in file types: "},
errScript: {errScript, 1, "error in script: "},
errStorage: {errStorage, 1, "error building storage"},
}
)
func exitErrorFor(id int) exitError {
e, ok := exitErrors[id]
if !ok {
return exitErrors[errUnknown]
}
return e
}
func exitErrorCode(id int) int {
e, ok := exitErrors[id]
if !ok {
return exitErrors[errUnknown].Exit
}
return e.Exit
}
func exitErrorInfo(id int) string {
e, ok := exitErrors[id]
if !ok {
return exitErrors[errUnknown].Description
}
return e.Description
}