errorutil

package
v0.0.0-...-4be01c1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dief

func Dief(err error, format string, values ...interface{})

func ErrorAs

func ErrorAs(src error, target error) (error, bool)

Dive into wrapped errors from src until return an error that casts to the target error or such error is not found nolint:golint

func ExpandError

func ExpandError(err error) interface{}

func LogErrorf

func LogErrorf(err error, format string, args ...interface{})

func LogFatalf

func LogFatalf(err error, format string, args ...interface{})

func MustSucceed

func MustSucceed(err error, msg ...string)

func TryToUnwrap

func TryToUnwrap(err error) error

Given an error, tries to unwrap it recursively until finds a "trivial" error which cannot be unwrapped anymore. It differs from errors.Unwrap() on returning the error itself in case it cannot be unwrapped, instead of nil

func UpdateErrorFromCall

func UpdateErrorFromCall(f func() error, err *error)

func UpdateErrorFromCloser

func UpdateErrorFromCloser(closer io.Closer, err *error)

UpdateErrorFromCloser is supposed to be used to close a io.Closer when a function exits, merging its error return into err, if any.

Types

type Chainable

type Chainable interface {
	Chain() ErrorChain
}

type Error

type Error struct {
	Line     int
	Filename string
	Msg      string
	Err      error
}

func Wrap

func Wrap(err error, args ...interface{}) *Error

Wrap an error adding more context such as filename and line where wrapping happened

func (*Error) Chain

func (e *Error) Chain() ErrorChain

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorChain

type ErrorChain []error

nolint: errname

func BuildChain

func BuildChain(outer, inner error) ErrorChain

func Chain

func Chain(c Chainable) ErrorChain

Return a chain of errors, from top to bottom of the "stack"

func (ErrorChain) Error

func (chain ErrorChain) Error() string

func (ErrorChain) JSON

func (chain ErrorChain) JSON() []JsonErrorObject

type JsonErrorObject

type JsonErrorObject struct {
	Error string `json:"error,omitempty"`
	File  string `json:"file,omitempty"`
	Line  int    `json:"line,omitempty"`
}

Jump to

Keyboard shortcuts

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