Documentation ¶
Overview ¶
Package handler implements handler for objects returned recovery() function.
Index ¶
- Constants
- func LogOutput(lvl int, s string) (err error)
- func NilNoop(err error) error
- func NoerrCallToDo(a []any) (yes bool)
- func PanicNoop(any)
- func PreProcess(errPtr *error, info *Info, a []any) error
- func Process(info *Info)
- func WorkToDo(r any, err *error) bool
- type CheckHandler
- type ErrorFn
- type Info
- type NilFn
- type PanicFn
Constants ¶
View Source
const ( // Wrapping is best default because we can be in the situation where we // have received meaningful sentinel error which we need to wrap, even // automatically. If we'd have used %v (no wrapping) we would lose the // sentinel error info and we couldn't use annotation for this error. // However, we should think about this more later from performance point of // view. WrapError = ": %w" )
Variables ¶
This section is empty.
Functions ¶
func NoerrCallToDo ¶ added in v0.9.5
NoerrCallToDo returns if we have the _exception case_, aka, func (noerr bool) where these handlers are called even normally only error handlers are called, i.e. those which have error to handle.
func PreProcess ¶ added in v0.8.12
PreProcess is currently used for err2 API like err2.Handle and .Catch.
- replaces the Process
func Process ¶
func Process(info *Info)
Process executes error handling logic. Panics and whole defer stack is included.
- err2.API functions call PreProcess and Process is exported for tests.
- That there is an error or a panic to handle i.e. that's taken care.
Types ¶
type CheckHandler ¶ added in v0.9.5
type CheckHandler = func(noerr bool)
CheckHandler = func(noerr bool, err error) error
type ErrorFn ¶ added in v1.0.0
func Pipeline ¶ added in v1.0.0
Pipeline is a helper to call several error handlers in a sequence.
defer err2.Handle(&err, err2.Pipeline(err2.Log, MapToHTTPErr))
func ToErrorFns ¶ added in v1.0.0
type Info ¶
type Info struct { Any any // panic transport object Err *error // error transport pointer (i.e. in/output) Format string // format string Args []any // args for format string printing // These are used if handler.Process caller sets them. If they aren't set // handler uses package level variables from tracer. ErrorTracer io.Writer // If nil tracer package's default is used. PanicTracer io.Writer // If nil tracer package's default is used. // These are called if handler.Process caller sets it. If they aren't set // default implementations are used. NOTE. We have to use both which means // that we get nilHandler call if recovery() is called by any other // handler then we call still ErrorFn and get the error from Any. It // goes for other way around: we get error but nilHandler is only one to // set, we use that for the error (which is accessed from the closure). ErrorFn // If nil default implementation is used. NilFn // If nil default (pre-defined here) implementation is used. PanicFn // If nil panic() is called. CheckHandler // this would be for cases where there isn't any error, but CallerName string // contains filtered or unexported fields }
Info tells to Process function how to proceed.
Click to show internal directories.
Click to hide internal directories.