-
Notifications
You must be signed in to change notification settings - Fork 1
/
exception.go
49 lines (41 loc) · 1.23 KB
/
exception.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
package m3lsh
import (
"runtime/debug"
"strconv"
"strings"
)
type exception interface {
Stacktrace() []string
setThread(threadInfo)
setStack([]stackTraceLine)
setMessage(string)
}
func formatException(ex exception) {
vals := strings.Split(string(debug.Stack()), "\n")
routineInfo := strings.Split(vals[0], " ")
routineID, _ := strconv.ParseInt(routineInfo[1], 10, 64)
routineState := routineInfo[2][1 : len(routineInfo[2])-2]
lines := make([]stackTraceLine, len(vals)/2)
for idx, line := range vals {
if idx == 0 || idx+1 == len(vals) {
continue
}
if idx%2 == 1 { // package and method
lines[idx/2] = stackTraceLine{}
if strings.Contains(line, ".") {
lines[idx/2].pkg = strings.Split(line, ".")[0]
lines[idx/2].method = strings.Split(strings.Split(line, ".")[1], "(")[0]
} else {
lines[idx/2].method = strings.Split(line, "(")[0]
lines[idx/2].pkg = "golang"
}
} else {
splitLine := strings.Split(strings.Trim(line, " \t"), " ")[0]
lines[idx/2-1].file = strings.Split(splitLine, ":")[0]
lines[idx/2-1].line, _ = strconv.ParseInt(strings.Split(splitLine, ":")[1], 10, 64)
}
}
thread := threadInfo{routineID: routineID, routineState: routineState}
ex.setStack(lines)
ex.setThread(thread)
}