buildStackTrace gets the stack trace from the outermost error and marks which frames correspond to which errors in the chain.
(err error)
| 89 | // buildStackTrace gets the stack trace from the outermost error and marks |
| 90 | // which frames correspond to which errors in the chain. |
| 91 | func buildStackTrace(err error) []stackFrame { |
| 92 | type stackTracer interface { |
| 93 | StackTrace() []uintptr |
| 94 | } |
| 95 | |
| 96 | type callers interface { |
| 97 | Callers() []uintptr |
| 98 | } |
| 99 | |
| 100 | var stack []uintptr |
| 101 | |
| 102 | //nolint:errorlint |
| 103 | switch t := err.(type) { |
| 104 | case stackTracer: |
| 105 | stack = t.StackTrace() |
| 106 | case callers: |
| 107 | stack = t.Callers() |
| 108 | default: |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | frames := make([]stackFrame, 0, len(stack)) |
| 113 | for _, pc := range stack { |
| 114 | fn := runtime.FuncForPC(pc) |
| 115 | if fn == nil { |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | file, line := fn.FileLine(pc) |
| 120 | frames = append(frames, stackFrame{ |
| 121 | File: file, |
| 122 | Line: line, |
| 123 | Function: fn.Name(), |
| 124 | }) |
| 125 | } |
| 126 | |
| 127 | return frames |
| 128 | } |
| 129 | |
| 130 | // getBuildInfo returns the Go version and Git commit hash. |
| 131 | func getBuildInfo() (string, string) { |
no test coverage detected