Last active
June 4, 2019 11:34
-
-
Save kamilogorek/4b16496f82920cd61826b14af3101034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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