Package errors
Overview ▹
Index ▹
type Client ¶
type Client struct { // RepanicDefault determines whether Catch will re-panic after recovering a // panic. This behavior can be overridden for an individual call to Catch using // the Repanic option. RepanicDefault bool // contains filtered or unexported fields }
func NewClient ¶
func NewClient(ctx context.Context, projectID, serviceName, serviceVersion string, useLogging bool, opts ...option.ClientOption) (*Client, error)
func (*Client) Catch ¶
func (c *Client) Catch(ctx context.Context, opt ...Option)
Catch tries to recover a panic; if it succeeds, it writes an error report. It should be called by deferring it, like any other function for recovering panics.
Catch can be called concurrently with other calls to Catch, Report or Reportf.
func (*Client) Close ¶
func (c *Client) Close() error
Close closes any resources held by the client. Close should be called when the client is no longer needed. It need not be called at program exit.
func (*Client) Report ¶
func (c *Client) Report(ctx context.Context, r *http.Request, v ...interface{})
Report writes an error report unconditionally, instead of only when a panic occurs. If r is non-nil, information from the Request is included in the error report.
Report can be called concurrently with other calls to Catch, Report or Reportf.
func (*Client) Reportf ¶
func (c *Client) Reportf(ctx context.Context, r *http.Request, format string, v ...interface{})
Reportf writes an error report unconditionally, instead of only when a panic occurs. If r is non-nil, information from the Request is included in the error report.
Reportf can be called concurrently with other calls to Catch, Report or Reportf.
type Option ¶
An Option is an optional argument to Catch.
type Option interface {
// contains filtered or unexported methods
}
func PanicFlag ¶
func PanicFlag(p *bool) Option
PanicFlag returns an Option that can inform Catch that a panic has occurred. If *p is true when Catch is called, an error report is made even if recover returns nil. This allows Catch to report an error for panic(nil). If p is nil, the option is ignored.
Here is an example of how to use PanicFlag:
func foo(ctx context.Context, ...) { hasPanicked := true defer errorsClient.Catch(ctx, errors.PanicFlag(&hasPanicked)) ... ... // We have reached the end of the function, so we're not panicking. hasPanicked = false }
func Repanic ¶
func Repanic(r bool) Option
Repanic returns an Option that determines whether Catch will re-panic after it reports an error. This overrides the default in the client.
func WithMessage ¶
func WithMessage(v ...interface{}) Option
WithMessage returns an Option that sets a message to be included in the error report, if one is made. v is converted to a string with fmt.Sprint.
func WithMessagef ¶
func WithMessagef(format string, v ...interface{}) Option
WithMessagef returns an Option that sets a message to be included in the error report, if one is made. format and v are converted to a string with fmt.Sprintf.
func WithRequest ¶
func WithRequest(r *http.Request) Option
WithRequest returns an Option that informs Catch or Report of an http.Request that is being handled. Information from the Request is included in the error report, if one is made.