errio

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 6 Imported by: 11

Documentation

Overview

Package errio contains custom error types to easily transfer errors between applications and output them to the user in a consistent way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureError

func CaptureError(err error, tags map[string]string) (string, chan error)

CaptureError captures an error and sends it to Sentry.

func CaptureErrorAndWait

func CaptureErrorAndWait(err error, tags map[string]string) string

CaptureErrorAndWait captures an error and sends it to Sentry and wait for that process to be finished.

func Error

func Error(err error) error

Error can be called to on any error to convert it to a PublicError if it is not already. If it is not yet a PublicError, an UnexpectedError is returned

func IsKnown

func IsKnown(err error) bool

IsKnown checks whether the given error is known.

func NewException

func NewException(err error, stacktrace *raven.Stacktrace) *raven.Exception

NewException returns a *raven.Exception for an error from this package. In contrary to raven.NewException, this function tries to retrieve the error type from the typer interface.

func StatusError

func StatusError(err error) error

StatusError can be called to on any error to convert it to a PublicStatusError if it is not already. If it is not yet a PublicError, an UnexpectedError is returned

Types

type ErrorCode

type ErrorCode struct {
	Code      string
	Namespace Namespace
}

ErrorCode contains a code that should be unique to the namespace it belongs to

func (ErrorCode) Error

func (c ErrorCode) Error(message string) PublicError

Error returns a PublicError with the given code and message

func (ErrorCode) ErrorPref

func (c ErrorCode) ErrorPref(message string) func(args ...interface{}) PublicError

ErrorPref returns a function that can be called with arguments to create a formatted error message

func (ErrorCode) Errorf

func (c ErrorCode) Errorf(message string, args ...interface{}) PublicError

Errorf works like fmt.Errorf to create an Error.

func (ErrorCode) StatusError

func (c ErrorCode) StatusError(message string, status int) PublicStatusError

StatusError creates a new PublicStatusError

func (ErrorCode) StatusErrorf

func (c ErrorCode) StatusErrorf(message string, status int, args ...interface{}) PublicStatusError

StatusErrorf works like fmt.Errorf to create a StatusError

type Namespace

type Namespace string

Namespace is a container for different errors and is used to distinguish between error codes. Using different namespaces helps you to keep error codes unique throughout your codebase. Typically, namespaces will carry the name of their package name or file name (without the .go part).

func (Namespace) Code

func (n Namespace) Code(code string) ErrorCode

Code returns a new ErrorCode

type PublicError

type PublicError struct {
	Namespace Namespace `json:"namespace,omitempty"`
	Code      string    `json:"code"`
	Message   string    `json:"message"`
}

PublicError is a wrapper around an error code and a error message. This allows clear error messaging and trace ability.

func UnexpectedError

func UnexpectedError(err error) PublicError

UnexpectedError represents an error that we did not expect. Unexpected errors are reported and logged.

func (PublicError) Append

func (e PublicError) Append(errs ...error) PublicError

Append appends multiple errors to an PublicError.

func (PublicError) Error

func (e PublicError) Error() string

PublicError implements the error interface.

func (PublicError) Type

func (e PublicError) Type() string

Type returns the type of the error as to be reported to Sentry.

type PublicStatusError

type PublicStatusError struct {
	PublicError `json:"error"`
	StatusCode  int `json:"-"`
}

PublicStatusError represents an http error. It contains an HTTP status code and can be json encoded in an HTTP response.

func UnexpectedStatusError

func UnexpectedStatusError(err error) PublicStatusError

UnexpectedStatusError is an error we did not expect, with http.StatusInternalServerError attached to it.

func Wrap

func Wrap(base PublicStatusError, errs ...error) PublicStatusError

Wrap wraps multiple errors with a PublicStatusError.

func (PublicStatusError) Append

func (e PublicStatusError) Append(errs ...error) PublicStatusError

Append appends multiple errors to a PublicStatusError

func (PublicStatusError) Error

func (e PublicStatusError) Error() string

Error implements the error interface.

func (PublicStatusError) Type

func (e PublicStatusError) Type() string

Type returns the type of the error as to be reported to Sentry.

Jump to

Keyboard shortcuts

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