MCPcopy Index your code
hub / github.com/bracesdev/errtrace / UnwrapFrame

Function UnwrapFrame

unwrap.go:17–33  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

15// Any error that has a method `TracePC() uintptr` will
16// contribute a frame to the trace.
17func 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}

Callers 6

wantErrFunction · 0.92
ExampleUnwrapFrameFunction · 0.92
TestUnwrapFrameFunction · 0.85
TestUnwrapFrame_badPCFunction · 0.85
buildTraceTreeFunction · 0.85

Calls 2

UnwrapMethod · 0.45
TracePCMethod · 0.45

Tested by 5

wantErrFunction · 0.74
ExampleUnwrapFrameFunction · 0.74
TestUnwrapFrameFunction · 0.68
TestUnwrapFrame_badPCFunction · 0.68