reporter

package
v0.0.0-...-2b7dcb4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2024 License: BSD-2-Clause Imports: 6 Imported by: 76

Documentation

Overview

package reporter provides a context.Context aware abstraction for shuttling errors and panics to third partys.

Index

Constants

View Source
const DefaultLevel = "error"

DefaultLevel is the default level a Report uses when reporting an error.

Variables

This section is empty.

Functions

func Flush

func Flush(ctx context.Context)

Flush the Reporter embedded within the context.Context

func Monitor

func Monitor(ctx context.Context)

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

func Report(ctx context.Context, err error) error

Report wraps the err as an Error and reports it the the Reporter embedded within the context.Context.

func ReportWithLevel

func ReportWithLevel(ctx context.Context, level string, err error) error

ReportWithLevel wraps the err as an Error and reports it the the Reporter embedded within the context.Context.

func WithReporter

func WithReporter(ctx context.Context, r Reporter) context.Context

WithReporter inserts a Reporter into 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

func (r *FallbackReporter) ReportWithLevel(ctx context.Context, level string, err error) error

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

func (h *LogReporter) ReportWithLevel(ctx context.Context, level string, err error) error

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

func (r MultiReporter) ReportWithLevel(ctx context.Context, level string, err error) error

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.

func FromContext

func FromContext(ctx context.Context) (Reporter, bool)

FromContext extracts a Reporter from a context.Context.

type ReporterFunc

type ReporterFunc func(context.Context, string, error) error

ReporterFunc is a function signature that conforms to the Reporter interface.

func (ReporterFunc) ReportWithLevel

func (f ReporterFunc) ReportWithLevel(ctx context.Context, level string, err error) error

Report implements the Reporter interface.

Directories

Path Synopsis
hb2
package hb2 is a Go package for sending errors to Honeybadger using the official client library
package hb2 is a Go package for sending errors to Honeybadger using the official client library

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL