reporter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2015 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var DefaultMax = 1024

DefaultMax is the default maximum number of lines to show from the backtrace.

Functions

func AddContext

func AddContext(ctx context.Context, key string, value interface{})

AddContext adds contextual information to the Request object.

func AddRequest

func AddRequest(ctx context.Context, req *http.Request)

AddRequest adds information from an http.Request to the Request object.

func Report

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

Report reports the error with the backtrace starting at the calling function.

func ReportWithSkip

func ReportWithSkip(ctx context.Context, err error, skip int) error

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.

func WithReporter

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

WithReporter inserts a Reporter into the context.Context.

Types

type BacktraceLine

type BacktraceLine struct {
	PC   uintptr
	File string
	Line int
}

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

func NewError(err error, skip int) *Error

NewError wraps err as an Error and generates a backtrace pointing at the caller of this function.

func NewErrorWithContext

func NewErrorWithContext(ctx context.Context, err error, skip int) *Error

NewErrorWithContext returns a new Error with contextual information added.

func (*Error) Error

func (e *Error) Error() string

Make error implement the error interface.

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) Report

func (r *FallbackReporter) Report(ctx context.Context, 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) Report

func (h *LogReporter) Report(ctx context.Context, err error) error

Report logs the error to the Logger.

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.

func (MultiReporter) Report

func (r MultiReporter) Report(ctx context.Context, 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 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.

func FromContext

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

FromContext extracts a Reporter from a context.Context.

type ReporterFunc

type ReporterFunc func(context.Context, error) error

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

func (ReporterFunc) Report

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

Report implements the Reporter interface.

Directories

Path Synopsis
package hb is a Go package from sending errors to Honeybadger.
package hb is a Go package from sending errors to Honeybadger.

Jump to

Keyboard shortcuts

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