Something went wrong. Try again.
Error-handling utilities missing from Go's standard library.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142package inspect
import "runtime"
func stackFrames(err error) []runtime.Frame { traced, ok := err.(interface{ StackTrace() []uintptr }) if !ok { return nil } pcs := traced.StackTrace() if len(pcs) == 0 { return nil } frames := runtime.CallersFrames(pcs) // Usually one frame per PC; append still accommodates expanded inline frames. stack := make([]runtime.Frame, 0, len(pcs)) for { frame, more := frames.Next() stack = append(stack, frame) if !more { return stack } }}
// sharedFrames compares resolved frames so distinct inlined calls are not merged.func sharedFrames(stack, parent []runtime.Frame) int { shared := 0 for shared < len(stack) && shared < len(parent) { a, b := stack[len(stack)-1-shared], parent[len(parent)-1-shared] if !sameFrame(a, b) { break } shared++ } return shared}
func sameFrame(a, b runtime.Frame) bool { return a.PC == b.PC && a.Function == b.Function && a.File == b.File && a.Line == b.Line}