-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack-error.go
69 lines (59 loc) · 1.45 KB
/
stack-error.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
package base
var callStackInstance *CallStack
func init() {
callStackInstance = NewCallStack()
}
// type errStack struct {
// stackPC []uintptr
// raw error
// }
// ErrorStack 错误堆栈信息
func ErrorStack(err error) error {
return ErrorStackSkip(err, 0)
// pcs := make([]uintptr, 32)
// // skip func StackError invocations
// count := runtime.Callers(2, pcs)
// return &errStack{
// raw: err,
// stackPC: pcs[:count],
// }
}
// ErrorStackSkip 错误堆栈信息
func ErrorStackSkip(err error, skip int) error {
return callStackInstance.WrapErrorSkip(err, skip+1)
// pcs := make([]uintptr, 32)
// // skip func StackError invocations
// count := runtime.Callers(2+skip, pcs)
// return &errStack{
// raw: err,
// stackPC: pcs[:count],
// }
}
// github.com/sirupsen/logrus
func (e *errStack) Error() string {
return e.call.error(e)
}
// func (e *errStack) Error() string {
// frames := runtime.CallersFrames(e.stackPC)
// var (
// f runtime.Frame
// more bool
// index int
// )
// errString := ""
// if e.raw != nil && e.raw.Error() != "" {
// errString = e.raw.Error() + "\n"
// }
// for {
// f, more = frames.Next()
// if index = strings.Index(f.File, "src"); index != -1 {
// // trim GOPATH or GOROOT prifix
// f.File = string(f.File[index+4:])
// }
// errString = fmt.Sprintf("%s%s\n\t%s:%d\n", errString, f.Function, f.File, f.Line)
// if !more {
// break
// }
// }
// return errString
// }