errors

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Err400BadRequest = HTTPStatusError{
						// contains filtered or unexported fields
	}
	Err405MethodNotAllowed = HTTPStatusError{
							// contains filtered or unexported fields
	}
	Err409Conflict = HTTPStatusError{
					// contains filtered or unexported fields
	}
	Err422UnprocessableEntity = HTTPStatusError{
								// contains filtered or unexported fields
	}
	Err499ClientClosedRequest = HTTPStatusError{
								// contains filtered or unexported fields
	}
	Err500InternalServerError = HTTPStatusError{
								// contains filtered or unexported fields
	}
	Err501NotImplemented = HTTPStatusError{
							// contains filtered or unexported fields
	}
)

Status sentinels. Each is a valid HTTPStatusError whose Error() renders the status string ("499 Client Closed Request" etc.). Useful as both bare cancellation tokens (ctx.Cancel(Err499...)) and as constructor receivers (Err400BadRequest.Errorf("invalid %s", x)).

View Source
var (
	As     = errors.As
	Unwrap = errors.Unwrap
)
View Source
var ErrExists = NewWithType[errExistsDisamb]("exists")

Functions

func AsHTTPError

func AsHTTPError(err error) (error, bool)

AsHTTPError walks err's chain for an HTTPRenderer and returns the wire-shaped error. HTTP handlers call this to convert a domain error into the response shape. Returns (nil, false) if no HTTP-tagged error is in the chain.

func CancelWithNotImplemented

func CancelWithNotImplemented(ctx interfaces.ActiveContext)

func ContextCancelWith499ClientClosedRequest

func ContextCancelWith499ClientClosedRequest(ctx interfaces.ActiveContext)

func ContextCancelWithBadRequestError

func ContextCancelWithBadRequestError(ctx interfaces.ActiveContext, err error)

func ContextCancelWithBadRequestf

func ContextCancelWithBadRequestf(
	ctx interfaces.ActiveContext,
	format string,
	values ...any,
)

func ContextCancelWithError

func ContextCancelWithError(ctx interfaces.ActiveContext, err error)

func ContextCancelWithErrorAndFormat

func ContextCancelWithErrorAndFormat(
	ctx interfaces.ActiveContext,
	err error,
	format string,
	values ...any,
)

func ContextCancelWithErrorf

func ContextCancelWithErrorf(
	ctx interfaces.ActiveContext,
	format string,
	values ...any,
)

func ContextCloseAfter

func ContextCloseAfter(ctx interfaces.ActiveContext, closer io.Closer)

func ContextContinueOrPanic

func ContextContinueOrPanic(ctx interfaces.ActiveContext)

func ContextFlushAfter

func ContextFlushAfter(ctx interfaces.ActiveContext, flusher Flusher)

func ContextMustClose

func ContextMustClose(ctx interfaces.ActiveContext, closer io.Closer)

func ContextMustFlush

func ContextMustFlush(ctx interfaces.ActiveContext, flusher Flusher)

func ContextSetCancelOnSIGHUP

func ContextSetCancelOnSIGHUP(ctx Context)

func ContextSetCancelOnSIGINT

func ContextSetCancelOnSIGINT(ctx Context)

func ContextSetCancelOnSIGTERM

func ContextSetCancelOnSIGTERM(ctx Context)

func Deferred

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

func DeferredCloseAndRename

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

func DeferredCloser

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

func DeferredFlusher

func DeferredFlusher(
	err *error,
	f Flusher,
)

func DeferredRecover

func DeferredRecover(err *error)

func DeferredYieldCloser

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

func ErrorWithStackf

func ErrorWithStackf(format string, args ...any) error

func Errorf

func Errorf(format string, args ...any) (err error)

func Is

func Is(err, target error) bool

func Is400BadRequest

func Is400BadRequest(err error) bool

Is400BadRequest reports whether err's chain carries HTTP 400.

func Is499ClientClosedRequest

func Is499ClientClosedRequest(err error) bool

Is499ClientClosedRequest reports whether err's chain carries HTTP 499.

func IsAny

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

func IsBrokenPipe

func IsBrokenPipe(err error) bool

func IsEOF

func IsEOF(err error) bool

func IsErrNotFound

func IsErrNotFound(err error) bool

func IsErrno

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

func IsExist

func IsExist(err error) bool

func IsHTTPError

func IsHTTPError(target error, statusCode hs.Code) bool

IsHTTPError reports whether err's chain carries the given status code. Uses errors.As against the HTTPStatusCarrier interface so it works across both HTTPStatusError (domain) and httpRendering (wire).

func IsNetTimeout

func IsNetTimeout(err error) (ok bool)

func IsNotExist

func IsNotExist(err error) bool

func IsNotNilAndNotEOF

func IsNotNilAndNotEOF(err error) bool

TODO remove

func IsReadlinkInvalidArgument

func IsReadlinkInvalidArgument(err error) bool

func IsSentinel

func IsSentinel(err, target error) bool

func IsStopIteration

func IsStopIteration(err error) bool

func IsTooManyOpenFiles

func IsTooManyOpenFiles(err error) bool

func IsTyped

func IsTyped[DISAMB any](err error) bool

func IsWithTimeout

func IsWithTimeout(err, target error, timeout time.Duration) bool

func Join

func Join(es ...error) error

func MakeContext

func MakeContext(in ConTeXT.Context) *context

func MakeContextDefault

func MakeContextDefault() *context

func MakeErrNotFound

func MakeErrNotFound(value interfaces.Stringer) error

func MakeErrNotFoundString

func MakeErrNotFoundString(s string) error

func MakeErrStopIteration

func MakeErrStopIteration() error

func Must

func Must(funk FuncErr)

func PanicIfError

func PanicIfError(err any)

func PrintHelpful

func PrintHelpful(printer interfaces.Printer, helpful Helpful)

func PrintStackTracerIfNecessary

func PrintStackTracerIfNecessary(
	printer interfaces.Printer,
	name string,
	err error,
	_ ...any,
)

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 WithoutStack

func WithoutStack(err error) error

func Wrap

func Wrap(err error) error

func WrapExceptSentinel

func WrapExceptSentinel(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. Direct value comparison is performed (`in == except`) rather than errors.Is.

func WrapExceptSentinelAsNil

func WrapExceptSentinelAsNil(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. Direct value comparison is performed (`in == except`) rather than errors.Is.

func WrapSkip

func WrapSkip(
	skip int,
	err error,
) error

func Wrapf

func Wrapf(err error, format string, values ...any) error

Types

type Context

type Context interface {
	interfaces.ActiveContext
	CauseWithStackFrames() (error, []stack_frame.Frame)
	Run(func(Context)) error

	// TODO extricate from *context and turn into generic function
	SetCancelOnSignals(signals ...os.Signal)
}

type ErrNotFound

type ErrNotFound struct {
	Value string
}

func GetErrNotFound

func GetErrNotFound(err error) (ErrNotFound, bool)

GetErrNotFound extracts the ErrNotFound from an error chain. Returns the typed error and true if found, zero value and false otherwise.

func (ErrNotFound) Error

func (err ErrNotFound) Error() string

func (ErrNotFound) GetErrorType

func (err ErrNotFound) GetErrorType() errNotFoundDisamb

func (ErrNotFound) Is

func (err ErrNotFound) Is(target error) (ok bool)

type ErrorsIs

type ErrorsIs interface {
	Is(error) bool
}

type Flusher

type Flusher interface {
	Flush() error
}

type FuncContext

type FuncContext = interfaces.FuncActiveContext

func MakeFuncContextFromFuncErr

func MakeFuncContextFromFuncErr(in FuncErr) FuncContext

func MakeFuncContextFromFuncNil

func MakeFuncContextFromFuncNil(in FuncNil) FuncContext

type FuncErr

type FuncErr = func() error

func MakeFuncErrFromFuncNil

func MakeFuncErrFromFuncNil(in FuncNil) FuncErr

type FuncIs

type FuncIs func(error) bool

func MakeIsErrno

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

type FuncNil

type FuncNil = func()

type FuncWithStackInfo

type FuncWithStackInfo struct {
	FuncErr
	stack_frame.Frame
}

type Group

type Group []error

func (Group) Error

func (group Group) Error() string

func (Group) Len

func (group Group) Len() int

func (Group) Unwrap

func (group Group) Unwrap() []error

type GroupBuilder

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

func MakeGroupBuilder

func MakeGroupBuilder(
	errs ...error,
) (groupBuilder *GroupBuilder)

TODO consider making a pool and return a repool func on construction

func (*GroupBuilder) Add

func (groupBuilder *GroupBuilder) Add(err error)

func (*GroupBuilder) Empty

func (groupBuilder *GroupBuilder) Empty() (ok bool)

func (*GroupBuilder) GetError

func (groupBuilder *GroupBuilder) GetError() error

func (*GroupBuilder) Len

func (groupBuilder *GroupBuilder) Len() int

func (*GroupBuilder) Reset

func (groupBuilder *GroupBuilder) Reset()

type HTTPRenderer

type HTTPRenderer interface {
	HTTPStatusCarrier
	HTTPRender() error
}

HTTPRenderer is the explicit transformer used at HTTP wire/UX boundaries to convert a domain error into its on-the-wire HTTP form. Domain code returns errors satisfying HTTPStatusCarrier; HTTP handlers/middleware call AsHTTPError(err) to obtain the rendered form.

type HTTPStatusCarrier

type HTTPStatusCarrier interface {
	error
	HTTPStatusCode() hs.Code
}

HTTPStatusCarrier is the semantic tag attached to errors that carry an HTTP status code. Detected via errors.As through wrapped chains.

type HTTPStatusError

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

HTTPStatusError carries an HTTP status code as semantics, not identity. Error() returns the wrapped message, leaving the HTTP rendering to HTTPRender() / AsHTTPError() at the wire boundary. This means CLI tools, log lines, and other non-HTTP consumers get useful output without needing to walk past hidden-wrapper layers.

func BadRequest

func BadRequest(err error) HTTPStatusError

BadRequest tags an existing error with HTTP 400. No-op if the chain already carries 400.

func BadRequestWrapf

func BadRequestWrapf(format string, args ...any) HTTPStatusError

BadRequestWrapf is an alias for BadRequestf retained for backwards compatibility; both behave identically (pre-#107 they were already the same).

func BadRequestf

func BadRequestf(format string, args ...any) HTTPStatusError

BadRequestf formats and tags with HTTP 400.

func Conflictf

func Conflictf(format string, args ...any) HTTPStatusError

Conflictf formats and tags with HTTP 409.

func MakeHTTPStatusError

func MakeHTTPStatusError(code hs.Code, underlying error) HTTPStatusError

MakeHTTPStatusError constructs an HTTPStatusError directly. Prefer the status-specific constructors (BadRequestf, Conflictf, …) where possible.

func NotImplementedf

func NotImplementedf(format string, args ...any) HTTPStatusError

NotImplementedf formats and tags with HTTP 501.

func UnprocessableEntityf

func UnprocessableEntityf(format string, args ...any) HTTPStatusError

UnprocessableEntityf formats and tags with HTTP 422.

func (HTTPStatusError) Error

func (e HTTPStatusError) Error() string

func (HTTPStatusError) Errorf

func (e HTTPStatusError) Errorf(format string, args ...any) HTTPStatusError

Errorf builds a new HTTPStatusError sharing this one's status, wrapping a newly-formatted error. Preserves the receiver-pattern constructor (Err422UnprocessableEntity.Errorf(...)) used by existing callers and tests.

func (HTTPStatusError) HTTPRender

func (e HTTPStatusError) HTTPRender() error

HTTPRender returns the wire-shaped error: Error() renders "HTTP: <status>" with the underlying still reachable via Unwrap.

func (HTTPStatusError) HTTPStatusCode

func (e HTTPStatusError) HTTPStatusCode() hs.Code

func (HTTPStatusError) Unwrap

func (e HTTPStatusError) Unwrap() error

func (HTTPStatusError) WithStack

func (e HTTPStatusError) WithStack() error

WithStack attaches a stack frame around this error.

func (HTTPStatusError) Wrap

func (e HTTPStatusError) Wrap(underlying error) HTTPStatusError

Wrap builds a new HTTPStatusError sharing this one's status, wrapping the given underlying error.

type Helpful

type Helpful interface {
	error
	GetErrorCause() []string
	GetErrorRecovery() []string
}

func WithHelp

func WithHelp(
	err error,
	cause []string,
	recovery []string,
) Helpful

type Signal

type Signal struct {
	os.Signal
}

func (Signal) Error

func (err Signal) Error() string

func (Signal) Is

func (err Signal) Is(target error) bool

type Typed

type Typed[DISAMB any] interface {
	error
	GetErrorType() DISAMB
}

func MakeTypedSentinel

func MakeTypedSentinel[DISAMB any](text string) (
	sentinel Typed[DISAMB],
	check func(error) bool,
)

MakeTypedSentinel creates a typed sentinel error and its checker function. This is a convenience helper to reduce boilerplate when creating package errors.

Usage:

type pkgErrDisamb struct{}
var (
    ErrMyError, IsMyError = errors.MakeTypedSentinel[pkgErrDisamb]("my error")
)

The returned sentinel implements errors.Typed[DISAMB] and can be checked with either the returned checker function or errors.IsTyped[DISAMB](err).

func NewWithType

func NewWithType[DISAMB any](text string) Typed[DISAMB]

func WrapWithType

func WrapWithType[DISAMB any](err error) Typed[DISAMB]

type UnwrapMany

type UnwrapMany = interfaces.ErrorManyUnwrapper

type UnwrapOne

type UnwrapOne = interfaces.ErrorOneUnwrapper

type WaitGroup

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

func MakeWaitGroupParallel

func MakeWaitGroupParallel() WaitGroup

func MakeWaitGroupSerial

func MakeWaitGroupSerial() WaitGroup

type WithStackInfo

type WithStackInfo[T any] struct {
	Contents T
	stack_frame.Frame
}

Source Files

  • context.go
  • context_sentinels.go
  • deferred.go
  • group.go
  • group_builder.go
  • helpful.go
  • http.go
  • http_util.go
  • interfaces.go
  • is.go
  • main.go
  • main_release.go
  • normal.go
  • sentinels.go
  • signal.go
  • wait_group_parallel.go
  • wait_group_serial.go
  • wrapped_helpful.go
  • wrapped_without_stack.go

Jump to

Keyboard shortcuts

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