GetReportableStackTrace extracts a stack trace embedded in the given error in the format suitable for Sentry reporting. This supports: - errors generated by github.com/pkg/errors (either generated locally or after transfer through the network), - errors generated with WithStack() in this package, -
(err error)
| 44 | // Note: Sentry wants the oldest call frame first, so |
| 45 | // the entries are reversed in the result. |
| 46 | func GetReportableStackTrace(err error) *ReportableStackTrace { |
| 47 | // If we have a stack trace in the style of github.com/pkg/errors |
| 48 | // (either from there or our own withStack), use it. |
| 49 | if st, ok := err.(errbase.StackTraceProvider); ok { |
| 50 | return convertPkgStack(st.StackTrace()) |
| 51 | } |
| 52 | |
| 53 | // If we have flattened a github.com/pkg/errors-style stack |
| 54 | // trace to a string, it will happen in the error's safe details |
| 55 | // and we need to parse it. |
| 56 | if sd, ok := err.(errbase.SafeDetailer); ok { |
| 57 | details := sd.SafeDetails() |
| 58 | if len(details) > 0 { |
| 59 | switch errbase.GetTypeKey(err) { |
| 60 | case pkgFundamental, pkgWithStackName, ourWithStackName: |
| 61 | return parsePrintedStack(details[0]) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // No conversion available - no stack trace. |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | type frame = sentry.Frame |
| 71 |
searching dependent graphs…