8 const stackTraceSize = 10
10 // StackFrame represents a single entry in a stack trace.
11 type StackFrame struct {
17 // String satisfies the fmt.Stringer interface.
18 func (f StackFrame) String() string {
19 return fmt.Sprintf("%s:%d - %s", f.File, f.Line, f.Func)
22 // Stack returns the stack trace of an error. The error must contain the stack
23 // trace, or wrap an error that has a stack trace,
24 func Stack(err error) []StackFrame {
25 if wErr, ok := err.(wrapperError); ok {
31 // getStack is a formatting wrapper around runtime.Callers. It returns a stack
32 // trace in the form of a StackFrame slice.
33 func getStack(skip int, size int) []StackFrame {
35 pc = make([]uintptr, size)
36 calls = runtime.Callers(skip+1, pc)
40 for i := 0; i < calls; i++ {
41 f := runtime.FuncForPC(pc[i])
42 file, line := f.FileLine(pc[i] - 1)
43 trace = append(trace, StackFrame{