Documentation ¶
Overview ¶
package reporter provides a context.Context aware abstraction for shuttling errors and panics to third partys.
Index ¶
- Constants
- func Flush(ctx context.Context)
- func Monitor(ctx context.Context)
- func Report(ctx context.Context, err error) error
- func ReportWithLevel(ctx context.Context, level string, err error) error
- func WithReporter(ctx context.Context, r Reporter) context.Context
- type FallbackReporter
- type LogReporter
- type MultiError
- type MultiReporter
- type Reporter
- type ReporterFunc
Constants ¶
const DefaultLevel = "error"
DefaultLevel is the default level a Report uses when reporting an error.
Variables ¶
This section is empty.
Functions ¶
func Monitor ¶
Monitors and reports panics. Useful in goroutines.
Note: this RE-THROWS the panic after logging it
Example:
ctx := reporter.WithReporter(context.Background(), hb2.NewReporter(hb2.Config{})) ... go func(ctx context.Context) { defer reporter.Monitor(ctx) ... panic("oh noes") // will report, then panic with a wrapped error. }(ctx)
func Report ¶
Report wraps the err as an Error and reports it the the Reporter embedded within the context.Context.
func ReportWithLevel ¶
ReportWithLevel wraps the err as an Error and reports it the the Reporter embedded within the context.Context.
Types ¶
type FallbackReporter ¶
type FallbackReporter struct { // The first reporter to call. Reporter Reporter // This reporter will be used to report an error if the first Reporter // fails for some reason. Fallback Reporter }
func (*FallbackReporter) Flush ¶
func (r *FallbackReporter) Flush()
func (*FallbackReporter) ReportWithLevel ¶
type LogReporter ¶
type LogReporter struct{}
LogReporter is a Handler that logs the error to a log.Logger.
func NewLogReporter ¶
func NewLogReporter() *LogReporter
func (*LogReporter) ReportWithLevel ¶
Report logs the error to the Logger.
type MultiError ¶
type MultiError struct {
Errors []error
}
MultiError 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.
func (MultiReporter) Flush ¶
func (r MultiReporter) Flush()
func (MultiReporter) ReportWithLevel ¶
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 stack trace and any contextual // information. Implementers should type assert the error to an *Error // if they want to report the stack trace. ReportWithLevel(context.Context, string, error) error }
Reporter represents an error handler.
type ReporterFunc ¶
ReporterFunc is a function signature that conforms to the Reporter interface.
func (ReporterFunc) ReportWithLevel ¶
Report implements the Reporter interface.