Skip to content

Instantly share code, notes, and snippets.

@axw
Last active January 30, 2019 10:22
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 axw/247b6f69d2da016bb21a5eb1be44e611 to your computer and use it in GitHub Desktop.
Save axw/247b6f69d2da016bb21a5eb1be44e611 to your computer and use it in GitHub Desktop.
Go 2 Error Inspection feedback: programmatic Frame inspection
The proposal provides a means of printing an error, including the source location.
In the proposal, this is the _only_ way of accessing the source location.
In the Elastic APM Go agent (https://github.com/elastic/apm-agent-go), we provide
users with a means of reporting unexpected errors, along with the source location,
in a structured format. As the proposal is, we would need to print and then parse;
and then the format is not well defined anyway.
It would be ideal if we could access the error's frame directly, and then given
a frame, access the source location directly (say, by providing a method to convert
the frame to a runtime.Frame). See feedback_example.go.
package errors
type errorString struct {
s string
frame Frame
}
func (e errorString) Frame() Frame {
return e.frame
}
type Frame struct {
// Make room for three PCs: the one we were asked for, what it called,
// and possibly a PC for skipPleaseUseCallersFrames. See:
// https://go.googlesource.com/go/+/032678e0fb/src/runtime/extern.go#169
frames [3]uintptr
}
// RuntimeFrame returns f as a runtime.Frame.
func (f Frame) RuntimeFrame() runtime.Frame {
if _, ok := frames.Next(); !ok {
return runtime.Frame{}
}
fr, ok := frames.Next()
if !ok {
return runtime.Frame{}
}
return fr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment