Documentation
¶
Overview ¶
package reporter provides a context.Context aware abstraction for shuttling errors and panics to third partys.
Index ¶
- Variables
- func AddContext(ctx context.Context, key string, value interface{})
- func AddRequest(ctx context.Context, req *http.Request)
- func Report(ctx context.Context, err error) error
- func ReportWithSkip(ctx context.Context, err error, skip int) error
- func WithReporter(ctx context.Context, r Reporter) context.Context
- type BacktraceLine
- type Error
- type FallbackReporter
- type LogReporter
- type MultiError
- type MultiReporter
- type Reporter
- type ReporterFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultMax = 1024
DefaultMax is the default maximum number of lines to show from the backtrace.
Functions ¶
func AddContext ¶
AddContext adds contextual information to the Request object.
func AddRequest ¶
AddRequest adds information from an http.Request to the Request object.
func ReportWithSkip ¶
ReportWithSkip wraps the err as an Error and reports it the the Reporter embedded within the context.Context. If err is nil, Report will return early, so this function is safe to call without performing a nill check on the error first. A skip value of 0 refers to the calling function.
Types ¶
type BacktraceLine ¶
A line from the backtrace.
type Error ¶
type Error struct { // The error that was generated. Err error // The backtrace. Backtrace []*BacktraceLine // Any freeform contextual information about that error. Context map[string]interface{} // If provided, an http request that generated the error. Request *http.Request }
Error wraps an error with additional information, like a backtrace, contextual information, and an http request if provided.
func NewError ¶
NewError wraps err as an Error and generates a backtrace pointing at the caller of this function.
func NewErrorWithContext ¶
NewErrorWithContext returns a new Error with contextual information added.
type FallbackReporter ¶
type LogReporter ¶
type LogReporter struct{}
LogReporter is a Handler that logs the error to a log.Logger.
func NewLogReporter ¶
func NewLogReporter() *LogReporter
type MultiError ¶
type MultiError struct {
Errors []error
}
MutliError is an error implementation that wraps multiple errors.
func (*MultiError) Error ¶
func (e *MultiError) Error() string
Error implements the error interface. It simply joins all of the individual error messages with a comma.
type MultiReporter ¶
type MultiReporter []Reporter
MultiReporter is an implementation of the Reporter interface that reports the error to multiple Reporters. If any of the individual error reporters returns an error, a MutliError will be returned.
type Reporter ¶
type Reporter interface { // Report reports the error to an external system. The provided error // could be an Error instance, which will contain additional information // about the error, including a backtrace and any contextual // information. Implementers should type assert the error to an *Error // if they want to report the backtrace. Report(context.Context, error) error }
Reporter represents an error handler.