MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / buildStackTrace

Function buildStackTrace

server/error_page.go:91–128  ·  view source on GitHub ↗

buildStackTrace gets the stack trace from the outermost error and marks which frames correspond to which errors in the chain.

(err error)

Source from the content-addressed store, hash-verified

89// buildStackTrace gets the stack trace from the outermost error and marks
90// which frames correspond to which errors in the chain.
91func 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.
131func getBuildInfo() (string, string) {

Callers 1

unwrapErrorChainFunction · 0.85

Calls 2

StackTraceMethod · 0.65
CallersMethod · 0.65

Tested by

no test coverage detected