-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic.go
37 lines (30 loc) · 607 Bytes
/
panic.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
package zorros
import (
"golang.org/x/xerrors"
"strings"
)
type zpanic struct{ err error }
func Panic(err error) interface{} {
return zpanic{err}
}
func (x zpanic) stringify(indepth bool) string {
s, e := stringifyError(x.err)
ns := []string{s}
for e != nil && indepth {
s, e = stringifyError(e)
ns = append(ns, s)
}
return strings.Join(ns, "\n")
}
func (x zpanic) Error() string {
return x.stringify(false)
}
func (x zpanic) String() string {
return x.stringify(true)
}
func (x zpanic) Unwrap() error {
if w, ok := x.err.(xerrors.Wrapper); ok {
return w.Unwrap()
}
return x.err
}