parsePrintedStack reverse-engineers a reportable stack trace from the result of printing a github.com/pkg/errors stack trace with format %+v.
(st string)
| 126 | // parsePrintedStack reverse-engineers a reportable stack trace from |
| 127 | // the result of printing a github.com/pkg/errors stack trace with format %+v. |
| 128 | func parsePrintedStack(st string) *ReportableStackTrace { |
| 129 | // A printed stack trace looks like a repetition of either: |
| 130 | // "unknown" |
| 131 | // or |
| 132 | // <result of fn.Name()> |
| 133 | // <tab><file>:<linenum> |
| 134 | // It's also likely to contain a heading newline character(s). |
| 135 | var frames []frame |
| 136 | lines := strings.Split(strings.TrimSpace(st), "\n") |
| 137 | for i := 0; i < len(lines); i++ { |
| 138 | nextI, file, line, fnName := parsePrintedStackEntry(lines, i) |
| 139 | i = nextI |
| 140 | |
| 141 | // Compose the frame. |
| 142 | frame := frame{ |
| 143 | AbsPath: file, |
| 144 | Filename: trimPath(file), |
| 145 | Lineno: line, |
| 146 | InApp: true, |
| 147 | Module: "unknown", |
| 148 | Function: fnName, |
| 149 | } |
| 150 | if fnName != "unknown" { |
| 151 | // Extract the function/module details. |
| 152 | frame.Module, frame.Function = functionName(fnName) |
| 153 | } |
| 154 | frames = append(frames, frame) |
| 155 | } |
| 156 | |
| 157 | if frames == nil { |
| 158 | return nil |
| 159 | } |
| 160 | |
| 161 | // Sentry wants the frames with the oldest first, so reverse them. |
| 162 | for i, j := 0, len(frames)-1; i < j; i, j = i+1, j-1 { |
| 163 | frames[i], frames[j] = frames[j], frames[i] |
| 164 | } |
| 165 | |
| 166 | return &ReportableStackTrace{Frames: frames} |
| 167 | } |
| 168 | |
| 169 | // parsePrintedStackEntry extracts the stack entry information |
| 170 | // in lines at position i. It returns the new value of i if more than |
no test coverage detected
searching dependent graphs…