Documentation
¶
Index ¶
- Variables
- func AsHTTPError(err error) (error, bool)
- func CancelWithNotImplemented(ctx interfaces.ActiveContext)
- func ContextCancelWith499ClientClosedRequest(ctx interfaces.ActiveContext)
- func ContextCancelWithBadRequestError(ctx interfaces.ActiveContext, err error)
- func ContextCancelWithBadRequestf(ctx interfaces.ActiveContext, format string, values ...any)
- func ContextCancelWithError(ctx interfaces.ActiveContext, err error)
- func ContextCancelWithErrorAndFormat(ctx interfaces.ActiveContext, err error, format string, values ...any)
- func ContextCancelWithErrorf(ctx interfaces.ActiveContext, format string, values ...any)
- func ContextCloseAfter(ctx interfaces.ActiveContext, closer io.Closer)
- func ContextContinueOrPanic(ctx interfaces.ActiveContext)
- func ContextFlushAfter(ctx interfaces.ActiveContext, flusher Flusher)
- func ContextMustClose(ctx interfaces.ActiveContext, closer io.Closer)
- func ContextMustFlush(ctx interfaces.ActiveContext, flusher Flusher)
- func ContextSetCancelOnSIGHUP(ctx Context)
- func ContextSetCancelOnSIGINT(ctx Context)
- func ContextSetCancelOnSIGTERM(ctx Context)
- func Deferred(err *error, ef func() error)
- func DeferredCloseAndRename(err *error, c io.Closer, oldpath, newpath string)
- func DeferredCloser(err *error, closer io.Closer)
- func DeferredFlusher(err *error, f Flusher)
- func DeferredRecover(err *error)
- func DeferredYieldCloser[T any](yield func(T, error) bool, closer io.Closer)
- func ErrorWithStackf(format string, args ...any) error
- func Errorf(format string, args ...any) (err error)
- func Is(err, target error) bool
- func Is400BadRequest(err error) bool
- func Is499ClientClosedRequest(err error) bool
- func IsAny(err error, funcTargets ...FuncIs) bool
- func IsBrokenPipe(err error) bool
- func IsEOF(err error) bool
- func IsErrNotFound(err error) bool
- func IsErrno(err error, targets ...syscall.Errno) (ok bool)
- func IsExist(err error) bool
- func IsHTTPError(target error, statusCode hs.Code) bool
- func IsNetTimeout(err error) (ok bool)
- func IsNotExist(err error) bool
- func IsNotNilAndNotEOF(err error) bool
- func IsReadlinkInvalidArgument(err error) bool
- func IsSentinel(err, target error) bool
- func IsStopIteration(err error) bool
- func IsTooManyOpenFiles(err error) bool
- func IsTyped[DISAMB any](err error) bool
- func IsWithTimeout(err, target error, timeout time.Duration) bool
- func Join(es ...error) error
- func MakeContext(in ConTeXT.Context) *context
- func MakeContextDefault() *context
- func MakeErrNotFound(value interfaces.Stringer) error
- func MakeErrNotFoundString(s string) error
- func MakeErrStopIteration() error
- func Must(funk FuncErr)
- func PanicIfError(err any)
- func PrintHelpful(printer interfaces.Printer, helpful Helpful)
- func PrintStackTracerIfNecessary(printer interfaces.Printer, name string, err error, _ ...any)
- func RunChildContextWithPrintTicker(parentContext Context, runFunc func(Context), printFunc func(time.Time), ...) (err error)
- func RunContextWithPrintTicker(context Context, runFunc func(Context), printFunc func(time.Time), ...) (err error)
- func WithoutStack(err error) error
- func Wrap(err error) error
- func WrapExceptSentinel(in error, except ...error) (err error)
- func WrapExceptSentinelAsNil(in error, except ...error) (err error)
- func WrapSkip(skip int, err error) error
- func Wrapf(err error, format string, values ...any) error
- type Context
- type ErrNotFound
- type ErrorsIs
- type Flusher
- type FuncContext
- type FuncErr
- type FuncIs
- type FuncNil
- type FuncWithStackInfo
- type Group
- type GroupBuilder
- type HTTPRenderer
- type HTTPStatusCarrier
- type HTTPStatusError
- func BadRequest(err error) HTTPStatusError
- func BadRequestWrapf(format string, args ...any) HTTPStatusError
- func BadRequestf(format string, args ...any) HTTPStatusError
- func Conflictf(format string, args ...any) HTTPStatusError
- func MakeHTTPStatusError(code hs.Code, underlying error) HTTPStatusError
- func NotImplementedf(format string, args ...any) HTTPStatusError
- func UnprocessableEntityf(format string, args ...any) HTTPStatusError
- func (e HTTPStatusError) Error() string
- func (e HTTPStatusError) Errorf(format string, args ...any) HTTPStatusError
- func (e HTTPStatusError) HTTPRender() error
- func (e HTTPStatusError) HTTPStatusCode() hs.Code
- func (e HTTPStatusError) Unwrap() error
- func (e HTTPStatusError) WithStack() error
- func (e HTTPStatusError) Wrap(underlying error) HTTPStatusError
- type Helpful
- type Signal
- type Typed
- type UnwrapMany
- type UnwrapOne
- type WaitGroup
- type WithStackInfo
Constants ¶
This section is empty.
Variables ¶
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)).
var ErrExists = NewWithType[errExistsDisamb]("exists")
Functions ¶
func AsHTTPError ¶
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 DeferredCloseAndRename ¶
func DeferredYieldCloser ¶
func Is400BadRequest ¶
Is400BadRequest reports whether err's chain carries HTTP 400.
func Is499ClientClosedRequest ¶
Is499ClientClosedRequest reports whether err's chain carries HTTP 499.
func IsHTTPError ¶
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 MakeContextDefault ¶
func MakeContextDefault() *context
func MakeErrNotFound ¶
func MakeErrNotFound(value interfaces.Stringer) error
func PrintHelpful ¶
func PrintHelpful(printer interfaces.Printer, helpful Helpful)
func PrintStackTracerIfNecessary ¶
func PrintStackTracerIfNecessary( printer interfaces.Printer, name string, err error, _ ...any, )
func RunChildContextWithPrintTicker ¶
func RunContextWithPrintTicker ¶
func WrapExceptSentinel ¶
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 ¶
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.
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 FuncContext ¶
type FuncContext = interfaces.FuncActiveContext
func MakeFuncContextFromFuncErr ¶
func MakeFuncContextFromFuncErr(in FuncErr) FuncContext
func MakeFuncContextFromFuncNil ¶
func MakeFuncContextFromFuncNil(in FuncNil) FuncContext
type FuncIs ¶
type FuncNil ¶
type FuncNil = func()
type FuncWithStackInfo ¶
type FuncWithStackInfo struct {
FuncErr
stack_frame.Frame
}
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 ¶
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 Signal ¶
type Typed ¶
func MakeTypedSentinel ¶
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).
type UnwrapMany ¶
type UnwrapMany = interfaces.ErrorManyUnwrapper
type UnwrapOne ¶
type UnwrapOne = interfaces.ErrorOneUnwrapper
type WaitGroup ¶
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