errutil

package
v0.0.0-...-1fa5987 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InternalServerError = NewHTTPError(http.StatusInternalServerError, "internal server error")

Functions

func Coalesce

func Coalesce(errors ...error) error

func ErrorWithStack

func ErrorWithStack(err error) string

func HTTPStatus

func HTTPStatus(err error) int

func RecoverTo

func RecoverTo(err *error)

Encapsulates the pattern of writing to a named err result value if recovered. Usage: `defer errutil.RecoverTo(&err)`.

func Recovering

func Recovering(f func() error) (err error)

Invokes f, recovering from any panics.

func ToError

func ToError(x any) error

Coerces non-nil values to errors, wrapping non-errors in a Panic structure.

func ToTracedError

func ToTracedError(r any) error

Like ToError, but wraps non-nil errors as a TracedError.

Types

type HTTPError

type HTTPError interface {
	error
	HTTPStatus() int
}

TODO: Stop abusing this for internal vs external errors.

func HTTPErrorf

func HTTPErrorf(status int, format string, v ...any) HTTPError

func NewHTTPError

func NewHTTPError(status int, message string) HTTPError

func WithHTTPStatus

func WithHTTPStatus(status int, err error) HTTPError

type Panic

type Panic struct {
	Value any
}

Implementation of the error interface for any panic value.

func (Panic) Error

func (err Panic) Error() string

type TracedError

type TracedError struct {
	// contains filtered or unexported fields
}

Pair a wrapped error with a stack trace.

func NewTracedError

func NewTracedError(err error, stack string) TracedError

func (TracedError) Stack

func (err TracedError) Stack() string

func (TracedError) Unwrap

func (err TracedError) Unwrap() error

Jump to

Keyboard shortcuts

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