errors

package
Version: v0.0.0-...-ce839f8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0 Imports: 5 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPreconditionViolated = errors.New("precondition is violated")

ErrPreconditionViolated is returned when the precondition is violated

Functions

func FilterOut

func FilterOut(err error, fns ...Matcher) error

FilterOut removes all errors that match any of the matchers from the input error. If the input is a singular error, only that error is tested. If the input implements the Aggregate interface, the list of errors will be processed recursively.

This can be used, for example, to remove known-OK errors (such as io.EOF or os.PathNotFound) from a list of errors.

func HandleHttpError

func HandleHttpError(c *gin.Context, err error)

func NewHttpError

func NewHttpError(status int, err interface{}) error

func Reduce

func Reduce(err error) error

Reduce will return err or, if err is an Aggregate and only has one item, the first item in the aggregate.

Types

type Aggregate

type Aggregate interface {
	error
	Errors() []error
}

Aggregate represents an object that contains multiple errors, but does not necessarily have singular semantic meaning.

func AggregateGoroutines

func AggregateGoroutines(funcs ...func() error) Aggregate

AggregateGoroutines runs the provided functions in parallel, stuffing all non-nil errors into the returned Aggregate. Returns nil if all the functions complete successfully.

func CreateAggregateFromMessageCountMap

func CreateAggregateFromMessageCountMap(m MessageCountMap) Aggregate

CreateAggregateFromMessageCountMap converts MessageCountMap Aggregate

func Flatten

func Flatten(agg Aggregate) Aggregate

Flatten takes an Aggregate, which may hold other Aggregates in arbitrary nesting, and flattens them all into a single Aggregate, recursively.

func NewAggregate

func NewAggregate(errlist []error) Aggregate

NewAggregate converts a slice of errors into an Aggregate interface, which is itself an implementation of the error interface. If the slice is empty, this returns nil. It will check if any of the element of input error list is nil, to avoid nil pointer panic when call Error().

type HttpError

type HttpError struct {
	Status     int    `json:"code"`
	ErrMessage string `json:"details"`
}

func (HttpError) Error

func (e HttpError) Error() string

type Matcher

type Matcher func(error) bool

Matcher is used to match errors. Returns true if the error matches.

type MessageCountMap

type MessageCountMap map[string]int

MessageCountMap contains occurance for each error message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL