sderr

package module
v0.0.0-...-52b04e8 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 12 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As finds the first error in the error tree that matches target, and if so, sets target to that error value and returns true.

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 will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

func At

func At(err error) (string, int)

At returns the file name and line the error originated from (if present)

func Cause

func Cause(in error, i int) error

Cause returns the i-th cause from the error value.

func Collect

func Collect(in error, pred func(error) bool) []error

Collect returns all errors in the error tree that matches the pred.

func CollectType

func CollectType(in, sample error) []error

CollectType returns all errors that are convertible to the error type of sample.

func Context

func Context(err error) *diag.Context

Context returns the errors diagnostic context, if the direct error value has a context.

func Errf

func Errf(msg string, vs ...interface{}) error

func Find

func Find(err, target error) error

Find walks the complete error tree, trying to find an error that matches target. The first error matching target is returned.

An error is matched with target, if the error is equal to the target, if error implements Is(error) bool that returns true for target, or target implements Is(error) bool such that Is(error) returne true.

func FindIf

func FindIf(in error, pred func(err error) bool) error

FindIf returns the first error in the error tree, that matches the given predicate.

func FindType

func FindType(in, sample error) error

FindType finds the first error the is convertible to the error type of sample.

func Is

func Is(err, target error) bool

Is walks the complete error tree, trying to find an error that matches target.

An error is matched with target, if the error is equal to the target, if error implements Is(error) bool that returns true for target, or target implements Is(error) bool such that Is(error) returne true.

Use `Find` to return the actual error value that would match.

func IsIf

func IsIf(err error, pred func(error) bool) bool

IsIf walkt the complete error try, trying to match an error with the given predicate.

Use `FindIf` to return the actual error value that would match.

func IsType

func IsType(in, sample error) bool

IsType checks if any error in the error tree is convertible to type of sample.

func Iter

func Iter(in error, fn func(err error) bool)

Iter iterates the complete error tree calling fn on each error value found. The user function fn can stop the iteration by returning false.

func New

func New(msg string) error

New returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.

func NumCauses

func NumCauses(in error) int

NumCauses returns the number of direct errors the error value wraps.

func PredType

func PredType(sample error) func(error) bool

PredType creates a predicate checking if the type of an error value matches the type of sample.

The predicate checks if the error type is equal or convertible to the sample type.

func Unwrap

func Unwrap(in error) error

Cause returns the first wrapped cause from the error value.

func Walk

func Walk(in error, fn func(error))

Walk walks the complete error tree.

func WalkEach

func WalkEach(errs []error, fn func(error))

WalkEach walks every single error value in the given array of errors.

func Wrap

func Wrap(cause error, msg string, vs ...interface{}) error

func WrapAll

func WrapAll(causes []error, msg string, vs ...interface{}) error

Types

type Builder

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

func With

func With(fields ...interface{}) *Builder

func WithDiagnosticContext

func WithDiagnosticContext(ctx *diag.Context) *Builder

func WithDiagnotics

func WithDiagnotics(ctx context.Context) *Builder

func WithStack

func WithStack() *Builder

func (*Builder) Errf

func (b *Builder) Errf(msg string, vs ...interface{}) error

func (*Builder) With

func (b *Builder) With(fields ...interface{}) *Builder

func (*Builder) WithDiagnosticContext

func (b *Builder) WithDiagnosticContext(ctx *diag.Context) *Builder

func (*Builder) WithDiagnotics

func (b *Builder) WithDiagnotics(ctx context.Context) *Builder

func (*Builder) WithStack

func (b *Builder) WithStack() *Builder

func (*Builder) Wrap

func (b *Builder) Wrap(cause error, msg string, vs ...interface{}) error

func (*Builder) WrapAll

func (b *Builder) WrapAll(causes []error, msg string, vs ...interface{}) error

type Frame

type Frame uintptr

func (Frame) File

func (f Frame) File() string

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

func (Frame) Function

func (f Frame) Function() string

func (Frame) Line

func (f Frame) Line() int

type StackTrace

type StackTrace []Frame

func Trace

func Trace(err error) StackTrace

Trace returns the stack trace, if the error value contains one.

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Jump to

Keyboard shortcuts

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