Skip to content

Instantly share code, notes, and snippets.

@kamilogorek kamilogorek/ex1.go
Last active Jun 4, 2019

Embed
What would you like to do?
func ExtractStacktrace(err error) *Stacktrace {
// https://github.com/pkg/errors
// Packages definitions:
// type Frame []uintptr
// type StackTrace []Frame
type stackTracer interface {
StackTrace() errors.StackTrace
}
var pcs []uintptr
if stacktrace, ok := err.(stackTracer); ok {
// won't compile, as types differ - hard dependency
pcs = stacktrace.StackTrace()
}
stacktrace := Stacktrace{
Frames: extractFrames(pcs),
}
return &stacktrace
}
func ExtractStacktrace(err error) *Stacktrace {
// https://github.com/pkg/errors
// Packages definitions:
// type Frame []uintptr
// type StackTrace []Frame
type stackTracer interface {
StackTrace() errors.StackTrace
}
var pcs []uintptr
if stacktrace, ok := err.(stackTracer); ok {
// will compile, but requires type coercion - hard dependency
st := stacktrace.StackTrace()
for _, val := range st {
pcs = append(pcs, uintptr(val))
}
}
stacktrace := Stacktrace{
Frames: extractFrames(pcs),
}
return &stacktrace
}
func ExtractStacktrace(err error) *Stacktrace {
// https://github.com/pkg/errors
// Packages definitions:
// type Frame []uintptr
// type StackTrace []Frame
type stackTracer interface {
StackTrace() []uintptr
}
var pcs []uintptr
if stacktrace, ok := err.(stackTracer); ok {
// won't read pcs, as interface is not satisfied - no dependency
pcs = stacktrace.StackTrace()
}
stacktrace := Stacktrace{
Frames: extractFrames(pcs),
}
return &stacktrace
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.