forked from reusee/socks5hs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr.go
47 lines (41 loc) · 739 Bytes
/
err.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
package socks5hs
import "fmt"
type Err struct {
Pkg string
Info string
Prev error
}
func (e *Err) Error() string {
if e.Prev == nil {
return fmt.Sprintf("%s: %s", e.Pkg, e.Info)
}
return fmt.Sprintf("%s: %s\n%v", e.Pkg, e.Info, e.Prev)
}
func me(err error, format string, args ...interface{}) *Err {
if len(args) > 0 {
return &Err{
Pkg: `socks5hs`,
Info: fmt.Sprintf(format, args...),
Prev: err,
}
}
return &Err{
Pkg: `socks5hs`,
Info: format,
Prev: err,
}
}
func ce(err error, format string, args ...interface{}) {
if err != nil {
panic(me(err, format, args...))
}
}
func ct(err *error) {
if p := recover(); p != nil {
if e, ok := p.(error); ok {
*err = e
} else {
panic(p)
}
}
}