Skip to content

Instantly share code, notes, and snippets.

@mdwhatcott
Created February 6, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdwhatcott/de0391b63408830198e009522f7071cb to your computer and use it in GitHub Desktop.
Save mdwhatcott/de0391b63408830198e009522f7071cb to your computer and use it in GitHub Desktop.
Go Stack Trace Error
type StackTraceError struct {
inner error
stack []byte
}
func NewStackTraceError(inner error) *StackTraceError {
return &StackTraceError{
inner: inner,
stack: debug.Stack(),
}
}
func (this *StackTraceError) Error() string {
return fmt.Sprintf("error: %q\nstack:\n%s", this.inner, this.stack)
}
func (this *StackTraceError) Unwrap() error {
return this.inner
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment