UnwrapFrame unwraps the outermost frame from the given error, returning it and the inner error. ok is true if the frame was successfully extracted, and false otherwise, or if the error is not an errtrace error. You can use this for structured access to trace information. Any error that has a metho
(err error)
| 15 | // Any error that has a method `TracePC() uintptr` will |
| 16 | // contribute a frame to the trace. |
| 17 | func UnwrapFrame(err error) (frame runtime.Frame, inner error, ok bool) { //nolint:revive // error is intentionally middle return |
| 18 | e, ok := err.(interface{ TracePC() uintptr }) |
| 19 | if !ok { |
| 20 | return runtime.Frame{}, err, false |
| 21 | } |
| 22 | |
| 23 | inner = errors.Unwrap(err) |
| 24 | frames := runtime.CallersFrames([]uintptr{e.TracePC()}) |
| 25 | f, _ := frames.Next() |
| 26 | if f == (runtime.Frame{}) { |
| 27 | // Unlikely, but if PC didn't yield a frame, |
| 28 | // just return the inner error. |
| 29 | return runtime.Frame{}, inner, false |
| 30 | } |
| 31 | |
| 32 | return f, inner, true |
| 33 | } |