This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.go
93 lines (72 loc) · 1.58 KB
/
check.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
package xerror
import (
"fmt"
"os"
)
func Panic(err error, args ...interface{}) {
if isErrNil(err) {
return
}
panic(handle(err, func(err *xerror) { err.Detail = fmt.Sprint(args...) }))
}
func PanicF(err error, msg string, args ...interface{}) {
if isErrNil(err) {
return
}
panic(handle(err, func(err *xerror) { err.Detail = fmt.Sprintf(msg, args...) }))
}
func PanicErr(ret interface{}, err error) interface{} {
if isErrNil(err) {
return ret
}
panic(handle(err))
}
func PanicBytes(ret []byte, err error) []byte {
if isErrNil(err) {
return ret
}
panic(handle(err))
}
func PanicStr(ret string, err error) string {
if isErrNil(err) {
return ret
}
panic(handle(err))
}
func Exit(err error, args ...interface{}) {
if isErrNil(err) {
return
}
p(handle(err, func(err *xerror) { err.Detail = fmt.Sprint(args...) }).debugString())
printStack()
os.Exit(1)
}
func ExitF(err error, msg string, args ...interface{}) {
if isErrNil(err) {
return
}
p(handle(err, func(err *xerror) { err.Detail = fmt.Sprintf(msg, args...) }).debugString())
printStack()
os.Exit(1)
}
func ExitErr(dat interface{}, err error) interface{} {
if isErrNil(err) {
return dat
}
p(handle(err).debugString())
printStack()
os.Exit(1)
return nil
}
func Wrap(err error, args ...interface{}) error {
if isErrNil(err) {
return nil
}
return handle(err, func(err *xerror) { err.Detail = fmt.Sprint(args...) })
}
func WrapF(err error, msg string, args ...interface{}) error {
if isErrNil(err) {
return nil
}
return handle(err, func(err *xerror) { err.Detail = fmt.Sprintf(msg, args...) })
}