errors

package
v0.0.0-...-791c77c Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 19 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	As     = errors.As
	Unwrap = errors.Unwrap
)
View Source
var (
	ErrNotImplemented = New("not implemented")
	ErrNotSupported   = New("not supported")
)
View Source
var (
	ErrFalse         = New("false")
	ErrTrue          = New("true")
	ErrStopIteration = New("stop iteration")
)
View Source
var New = xerrors.New

Functions

func BadRequest

func BadRequest(err error) *errBadRequestWrap

func BadRequestPrefix

func BadRequestPrefix(preamble string, err error) *errBadRequestPreamble

func BadRequestf

func BadRequestf(fmt string, args ...any) *errBadRequestWrap

func Deferred

func Deferred(
	err *error,
	ef func() error,
)

func DeferredChan

func DeferredChan(
	ch chan<- error,
	f func() error,
)

func DeferredChanError

func DeferredChanError(
	err *error,
	ch <-chan error,
)

func DeferredCloseAndRename

func DeferredCloseAndRename(err *error, c io.Closer, oldpath, newpath string)

func DeferredCloser

func DeferredCloser(
	err *error,
	c io.Closer,
)

func DeferredFlusher

func DeferredFlusher(
	err *error,
	f Flusher,
)

func DeferredYieldCloser

func DeferredYieldCloser[T any](
	yield func(T, error) bool,
	c io.Closer,
)

func ErrorWithStackf

func ErrorWithStackf(f string, values ...interface{}) (err error)

func Errorf

func Errorf(f string, values ...interface{}) (err error)

func Implement

func Implement() (err error)

func Is

func Is(err, target error) bool

func IsAny

func IsAny(err error, ises ...FuncIs) bool

func IsAsNilOrWrapf

func IsAsNilOrWrapf(
	err error,
	target error,
	format string,
	values ...any,
) (out error)

func IsBadRequest

func IsBadRequest(err error) bool

func IsBrokenPipe

func IsBrokenPipe(err error) bool

func IsEOF

func IsEOF(err error) bool

func IsErrFalse

func IsErrFalse(err error) bool

func IsErrTrue

func IsErrTrue(err error) bool

func IsErrno

func IsErrno(err error, targets ...syscall.Errno) (ok bool)

func IsExist

func IsExist(err error) bool

func IsNetTimeout

func IsNetTimeout(err error) (ok bool)

func IsNotExist

func IsNotExist(err error) bool

func IsNotNilAndNotEOF

func IsNotNilAndNotEOF(err error) bool

func IsStopIteration

func IsStopIteration(err error) bool

func IsTooManyOpenFiles

func IsTooManyOpenFiles(err error) bool

func IterWrapped

func IterWrapped[T any](err error) iter.Seq2[T, error]

func Join

func Join(es ...error) error

func MakeContext

func MakeContext(in ConTeXT.Context) *context

func MakeContextDefault

func MakeContextDefault() *context

func MakeErrStopIteration

func MakeErrStopIteration() error

func MakeMulti

func MakeMulti(errs ...error) (em *multi)

func NewNormal

func NewNormal(v string) errNormal

TODO refactor NewNormal into something that combines helpful and stack trace

func PanicIfError

func PanicIfError(err interface{})

func PrintHelpful

func PrintHelpful(printer interfaces.Printer, helpful Helpful)

func RunChildContextWithPrintTicker

func RunChildContextWithPrintTicker(
	parentContext Context,
	runFunc func(Context),
	printFunc func(time.Time),
	duration time.Duration,
) (err error)

func RunContextWithPrintTicker

func RunContextWithPrintTicker(
	context Context,
	runFunc func(Context),
	printFunc func(time.Time),
	duration time.Duration,
) (err error)

func SetTesting

func SetTesting()

func Wrap

func Wrap(in error) error

func WrapExcept

func WrapExcept(in error, except ...error) (err error)

wrap the error with stack info unless it's one of the provided `except` errors, in which case return that bare error

func WrapExceptAsNil

func WrapExceptAsNil(in error, except ...error) (err error)

wrap the error with stack info unless it's one of the provided `except` errors, in which case return nil.

func WrapN

func WrapN(n int, in error) (err error)

func WrapSkip

func WrapSkip(
	skip int,
	in error,
) (err *stackWrapError)

func Wrapf

func Wrapf(in error, f string, values ...any) error

Types

type Context

type Context interface {
	ConTeXT.Context

	Cause() error
	Continue() bool
	ContinueOrPanicOnDone()
	SetCancelOnSIGINT()
	SetCancelOnSIGHUP()
	SetCancelOnSignals(signals ...os.Signal)
	Run(f func(Context)) error

	// `After` runs a function after the context is complete (regardless of any
	// errors). `After`s are run in the reverse order of when they are called, like
	// defers but on a whole-program level.
	After(f func() error)
	AfterWithContext(f func(Context) error)

	// `Must` executes a function even if the context has been cancelled. If the
	// function returns an error, `Must` cancels the context and offers a heartbeat to
	// panic. It is meant for defers that must be executed, like closing files,
	// flushing buffers, releasing locks.
	Must(f func() error)
	MustWithContext(f func(Context) error)
	MustClose(closer io.Closer)
	MustFlush(flusher Flusher)
	Cancel()

	CancelWithError(err error)
	CancelWithErrorAndFormat(err error, f string, values ...any)
	CancelWithErrorf(f string, values ...any)
	CancelWithBadRequestError(err error)
	CancelWithBadRequestf(f string, values ...any)
	CancelWithNotImplemented()
}

type ContextWithEnv

type ContextWithEnv[T any] struct {
	Context
	Env T
}

type ErrBadRequest

type ErrBadRequest interface {
	IsBadRequest()
}

type Flusher

type Flusher interface {
	Flush() error
}

type Func

type Func func() error

func MakeNilFunc

func MakeNilFunc(in func()) Func

type FuncIs

type FuncIs func(error) bool

func MakeIsErrno

func MakeIsErrno(targets ...syscall.Errno) FuncIs

type FuncWithStackInfo

type FuncWithStackInfo struct {
	Func
	StackFrame
}

type Helpful

type Helpful interface {
	error
	GetHelpfulError() Helpful
	ErrorCause() []string
	ErrorRecovery() []string
}

type Multi

type Multi interface {
	error
	Add(error)
	Empty() bool
	Reset()
	GetMultiError() Multi
	GetError() error
	Errors() []error
	interfaces.Lenner
}

type Retryable

type Retryable interface {
	GetRetryableError() Retryable
	Recover(RetryableContext, error)
}

type RetryableContext

type RetryableContext interface {
	Context
	Retry()
}

type Signal

type Signal struct {
	os.Signal
}

func (Signal) Error

func (err Signal) Error() string

type StackFrame

type StackFrame struct {
	Package     string
	Function    string
	Filename    string
	RelFilename string
	Line        int
	// contains filtered or unexported fields
}

func MakeStackFrame

func MakeStackFrame(skip int) (si StackFrame, ok bool)

func MakeStackFrameFromFrame

func MakeStackFrameFromFrame(runtimeFrame runtime.Frame) (frame StackFrame)

func MakeStackFrames

func MakeStackFrames(skip, count int) (frames []StackFrame)

func MustStackFrame

func MustStackFrame(skip int) StackFrame

func (StackFrame) Errorf

func (si StackFrame) Errorf(f string, values ...any) (err error)

func (StackFrame) FileNameLine

func (si StackFrame) FileNameLine() string

func (StackFrame) String

func (frame StackFrame) String() string

func (StackFrame) StringLogLine

func (frame StackFrame) StringLogLine() string

func (StackFrame) StringNoFunctionName

func (si StackFrame) StringNoFunctionName() string

func (StackFrame) Wrap

func (frame StackFrame) Wrap(in error) (err error)

If the frame is non-zero, return a wrapped error. Otherwise return the input error unwrapped.

func (StackFrame) Wrapf

func (si StackFrame) Wrapf(in error, f string, values ...any) (err error)

type StackTracer

type StackTracer interface {
	error
	ShouldShowStackTrace() bool
}

TODO refactor / remove?

type WaitGroup

type WaitGroup interface {
	Do(Func) bool
	DoAfter(Func)
	GetError() error
}

func MakeWaitGroupParallel

func MakeWaitGroupParallel() WaitGroup

func MakeWaitGroupSerial

func MakeWaitGroupSerial() WaitGroup

type WithStackInfo

type WithStackInfo[T any] struct {
	Contents T
	StackFrame
}

Jump to

Keyboard shortcuts

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