gg_errors

package
v0.2.62 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Errors      []error
	ErrorFormat ErrorFormatFunc
}

func (*Error) Error

func (instance *Error) Error() string

func (*Error) ErrorOrNil

func (instance *Error) ErrorOrNil() error

ErrorOrNil returns an error interface if this Error represents a list of errors, or returns nil if the list of errors is empty. This function is useful at the end of accumulation to make sure that the value returned represents the existence of errors.

func (*Error) GoString

func (instance *Error) GoString() string

func (Error) Len

func (instance Error) Len() int

Len implements sort.Interface function for length

func (Error) Less

func (instance Error) Less(i, j int) bool

Less implements sort.Interface function for determining order

func (Error) Swap

func (instance Error) Swap(i, j int)

Swap implements sort.Interface function for swapping elements

func (*Error) Unwrap

func (instance *Error) Unwrap() error

Unwrap returns an error from Error (or nil if there are no errors). This error returned will further support Unwrap to get the next error, etc. The order will match the order of Errors in the lygo_errors.Error at the time of calling.

The resulting error supports errors.As/Is/Unwrap so you can continue to use the stdlib errors package to introspect further.

This will perform a shallow copy of the errors slice. Any errors appended to this error after calling Unwrap will not be available until a new Unwrap is called on the lygo_errors.Error.

func (*Error) WrappedErrors

func (instance *Error) WrappedErrors() []error

WrappedErrors returns the list of errors that this Error is wrapping. It is an implementation of the errwrap.Wrapper interface so that lygo_errors.Error can be used with that library.

This method is not safe to be called concurrently and is no different than accessing the Errors field directly. It is implemented only to satisfy the errwrap.Wrapper interface.

type ErrorFormatFunc

type ErrorFormatFunc func([]error) string

ErrorFormatFunc turn the list of errors into a string.

type ErrorsHelper

type ErrorsHelper struct {
}
var Errors *ErrorsHelper

func (*ErrorsHelper) Append

func (instance *ErrorsHelper) Append(err error, errs ...error) *Error

Append is a helper function that will append more errors onto an Error in order to create a larger multi-error.

If err is not a lygo_errors.Error, then it will be turned into one. If any of the errs are multierr.Error, they will be flattened one level into err. Any nil errors within errs will be ignored. If err is nil, a new *Error will be returned.

func (*ErrorsHelper) Cause

func (instance *ErrorsHelper) Cause(err error) error

Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.

func (*ErrorsHelper) Contains

func (instance *ErrorsHelper) Contains(err error, msg string) bool

Contains checks if the given error contains an error with the message msg. If err is not a wrapped error, this will always return false unless the error itself happens to match this msg.

func (*ErrorsHelper) ContainsType

func (instance *ErrorsHelper) ContainsType(err error, v interface{}) bool

ContainsType checks if the given error contains an error with the same concrete type as v. If err is not a wrapped error, this will check the err itself.

func (*ErrorsHelper) Errorf

func (instance *ErrorsHelper) Errorf(format string, args ...interface{}) error

Errorf formats according to a format specifier and returns the string as a value that satisfies error. Errorf also records the stack trace at the point it was called.

func (*ErrorsHelper) Flatten

func (instance *ErrorsHelper) Flatten(err error) error

Flatten flattens the given error, merging any *Errors together into a single *Error.

func (*ErrorsHelper) Get

func (instance *ErrorsHelper) Get(err error, msg string) error

Get is the same as GetAll but returns the deepest matching error.

func (*ErrorsHelper) GetAll

func (instance *ErrorsHelper) GetAll(err error, msg string) []error

GetAll gets all the errors that might be wrapped in err with the given message. The order of the errors is such that the outermost matching error (the most recent wrap) is index zero, and so on.

func (*ErrorsHelper) GetAllType

func (instance *ErrorsHelper) GetAllType(err error, v interface{}) []error

GetAllType gets all the errors that are the same type as v.

The order of the return value is the same as described in GetAll.

func (*ErrorsHelper) GetType

func (instance *ErrorsHelper) GetType(err error, v interface{}) error

GetType is the same as GetAllType but returns the deepest matching error.

func (*ErrorsHelper) ListFormatFunc

func (instance *ErrorsHelper) ListFormatFunc(list []error) string

ListFormatFunc is a basic formatter that outputs the number of errors that occurred along with a bullet point list of the errors.

func (*ErrorsHelper) NewError

func (instance *ErrorsHelper) NewError(message string) error

NewError returns an error with the supplied message. NewError also records the stack trace at the point it was called.

func (*ErrorsHelper) Prefix

func (instance *ErrorsHelper) Prefix(err error, prefix string) error

Prefix is a helper function that will prefix some text to the given error. If the error is a lygo_errors.Error, then it will be prefixed to each wrapped error.

This is useful to use when appending multiple lygo_errors together in order to give better scoping.

func (*ErrorsHelper) Walk

func (instance *ErrorsHelper) Walk(err error, cb WalkFunc)

Walk walks all the wrapped errors in err and calls the callback. If err isn't a wrapped error, this will be called once for err. If err is a wrapped error, the callback will be called for both the wrapper that implements error as well as the wrapped error itself.

func (*ErrorsHelper) WithMessage

func (instance *ErrorsHelper) WithMessage(err error, message string) error

WithMessage annotates err with a new message. If err is nil, WithMessage returns nil.

func (*ErrorsHelper) WithMessagef

func (instance *ErrorsHelper) WithMessagef(err error, format string, args ...interface{}) error

WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.

func (*ErrorsHelper) WithStack

func (instance *ErrorsHelper) WithStack(err error) error

WithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.

func (*ErrorsHelper) Wrap

func (instance *ErrorsHelper) Wrap(outer, inner error) error

Wrap defines that outer wraps inner, returning an error type that can be cleanly used with the other methods in this package, such as Contains, GetAll, etc.

This function won't modify the error message at all (the outer message will be used).

func (*ErrorsHelper) WrapWithStack

func (instance *ErrorsHelper) WrapWithStack(err error, message string) error

WrapWithStack returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func (*ErrorsHelper) WrapWithStackf

func (instance *ErrorsHelper) WrapWithStackf(err error, format string, args ...interface{}) error

WrapWithStackf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.

func (*ErrorsHelper) Wrapf

func (instance *ErrorsHelper) Wrapf(format string, err error) error

Wrapf wraps an error with a formatting message. This is similar to using `fmt.Errorf` to wrap an error. If you're using `fmt.Errorf` to wrap errors, you should replace it with this.

format is the format of the error message. The string '{{err}}' will be replaced with the original error message.

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

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

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

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

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

type WalkFunc

type WalkFunc func(error)

WalkFunc is the callback called for Walk.

type Wrapper

type Wrapper interface {
	WrappedErrors() []error
}

Wrapper is an interface that can be implemented by custom types to have all the Contains, Get, etc. functions in errwrap work.

When Walk reaches a Wrapper, it will call the callback for every wrapped error in addition to the wrapper itself. Since all the top-level functions in errwrap use Walk, this means that all those functions work with your custom type.

Jump to

Keyboard shortcuts

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