merrors

package
v0.0.0-...-6b73929 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrettyPrint

func PrettyPrint(w io.Writer, err Error) error

PrettyPrint prints the same information as multiError.Error() method but with newlines and indentation targeted for humans.

Types

type Error

type Error interface {
	error

	// Errors returns underlying errors.
	Errors() []error

	// As finds the first error in multiError slice of error chains that matches target, and if so, sets
	// target to that error value and returns true. Otherwise, it returns false.
	//
	// An error matches target if the error's concrete value is assignable to the value
	// pointed to by target, or if the error has a method As(interface{}) bool such that
	// As(target) returns true. In the latter case, the As method is responsible for
	// setting target.
	As(target interface{}) bool
	// Is returns true if any error in multiError's slice of error chains matches the given target or
	// if the target is of multiError type.
	//
	// An error is considered to match a target if it is equal to that target or if
	// it implements a method Is(error) bool such that Is(target) returns true.
	Is(target error) bool
	// Count returns the number of multi error' errors that match the given target.
	// Matching is defined as in Is method.
	Count(target error) int
}

Error is extended error interface that allows to use returned read-only multi error in more advanced ways.

func AsMulti

func AsMulti(err error) (Error, bool)

AsMulti casts error to multi error read only interface. It returns multi error and true if error matches multi error as defined by As method. If returns false if no multi error can be found.

func Merge

func Merge(errs []Error) Error

Merge merges multiple Error to single one, but joining all errors together. NOTE: Nested multi errors are not merged.

type NilOrMultiError

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

NilOrMultiError type allows combining multiple errors into one.

func New

func New(errs ...error) *NilOrMultiError

New returns NilOrMultiError with provided errors added if not nil.

func (*NilOrMultiError) Add

func (e *NilOrMultiError) Add(errs ...error)

Add adds single or many errors to the error list. Each error is added only if not nil. If the error is a multiError type, the errors inside multiError are added to the main NilOrMultiError.

func (NilOrMultiError) Err

func (e NilOrMultiError) Err() Error

Err returns the error list as an Error (also implements error) or nil if it is empty.

Jump to

Keyboard shortcuts

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