/
errmanager.go
40 lines (36 loc) · 978 Bytes
/
errmanager.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
package console
import (
"flag"
"os"
)
const (
// ExitSuccess code represents exit when success
ExitSuccess = iota
// ExitError code represents exit when error occur
ExitError
// ExitBadConnection code represents exit when bad connection
ExitBadConnection
// ExitInvalidInput code represents for txn, watch command
ExitInvalidInput
// ExitBadFeature code represents provided a valid flag with an unsupported value
ExitBadFeature
// ExitInterrupted code represents exit the code get interrupted
ExitInterrupted
// ExitIO code represents exit when io error
ExitIO
// ExitBadArgs code represents exit when arguments are not right
ExitBadArgs = 128
)
// ExitWithError Exit Command with error
func ExitWithError(code int, err error) {
StopLoading()
Logger.Error(err.Error())
// check if running test
if flag.Lookup("test.v") == nil {
// kill the process (when using gvel through command line)
os.Exit(code)
} else {
// just panic
panic(code)
}
}