MCPcopy Index your code
hub / github.com/go-errors/errors / parsePanicFrame

Function parsePanicFrame

parse_panic.go:80–127  ·  view source on GitHub ↗

The lines we're passing look like this: main.(*foo).destruct(0xc208067e98) 0/go/src/github.com/bugsnag/bugsnag-go/pan/main.go:22 +0x151

(name string, line string, createdBy bool)

Source from the content-addressed store, hash-verified

78// main.(*foo).destruct(0xc208067e98)
79// /0/go/src/github.com/bugsnag/bugsnag-go/pan/main.go:22 +0x151
80func parsePanicFrame(name string, line string, createdBy bool) (*StackFrame, error) {
81 idx := strings.LastIndex(name, "(")
82 if idx == -1 && !createdBy {
83 return nil, Errorf("bugsnag.panicParser: Invalid line (no call): %s", name)
84 }
85 if idx != -1 {
86 name = name[:idx]
87 }
88 pkg := ""
89
90 if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 {
91 pkg += name[:lastslash] + "/"
92 name = name[lastslash+1:]
93 }
94 if period := strings.Index(name, "."); period >= 0 {
95 pkg += name[:period]
96 name = name[period+1:]
97 }
98
99 name = strings.Replace(name, "·", ".", -1)
100
101 if !strings.HasPrefix(line, "\t") {
102 return nil, Errorf("bugsnag.panicParser: Invalid line (no tab): %s", line)
103 }
104
105 idx = strings.LastIndex(line, ":")
106 if idx == -1 {
107 return nil, Errorf("bugsnag.panicParser: Invalid line (no line number): %s", line)
108 }
109 file := line[1:idx]
110
111 number := line[idx+1:]
112 if idx = strings.Index(number, " +"); idx > -1 {
113 number = number[:idx]
114 }
115
116 lno, err := strconv.ParseInt(number, 10, 32)
117 if err != nil {
118 return nil, Errorf("bugsnag.panicParser: Invalid line (bad line number): %s", line)
119 }
120
121 return &StackFrame{
122 File: file,
123 LineNumber: int(lno),
124 Package: pkg,
125 Name: name,
126 }, nil
127}

Callers 1

ParsePanicFunction · 0.85

Calls 1

ErrorfFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…