Documentation ¶
Overview ¶
© 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) ISC License
Index ¶
- Variables
- func AddToPanic(panicValue interface{}, additionalErr error) (err error)
- func Annotation() (annotation string)
- func EnsureError(panicValue interface{}) (err error)
- func HandleErrp(fn func(), errp *error)
- func HandlePanic(fn func()) (err error)
- func HandleParlError(fn func(), storeError func(err error))
- func Log(format string, a ...any)
- func NoOnError(err error)
- func Recover(annotation string, errp *error, onError func(error))
- func Recover2(annotation string, errp *error, onError func(error))
- func RecoverInvocationPanic(fn func(), errp *error)
- func Sprintf(format string, a ...interface{}) string
- type Go
Constants ¶
This section is empty.
Variables ¶
var ErrEndCallbacks = errors.New("end callbacks error")
ErrEndCallbacks indicates upon retun from a callback function that no more callbacks are desired. It does not indicate an error and is not returned as an error by any other function than the callback.
callback invocations may be thread-safe, re-entrant and panic-handling but this deopends on the callback-invoking implementation used.
if errors.Is(err, parl.ErrEndCallbacks) { …
var ErrErrpNil = errors.New("errp cannot be nil")
ErrErrpNil indicates that a function with an error pointer argument received an errp nil value.
if errors.Is(err, ErrErrpNil) …
Functions ¶
func AddToPanic ¶
AddToPanic takes a recover() value and adds it to additionalErr.
func Annotation ¶
func Annotation() (annotation string)
Annotation provides a default annotation [base package].[function]: "mypackage.MyFunc"
func EnsureError ¶
func EnsureError(panicValue interface{}) (err error)
AddToPanic ensures that a recover() value is an error or nil.
func HandleErrp ¶
func HandleErrp(fn func(), errp *error)
HandleErrp recovers from a panic in fn storing at *errp. HandleErrp is deferable.
func HandlePanic ¶
func HandlePanic(fn func()) (err error)
HandlePanic recovers from panic in fn returning error.
func HandleParlError ¶
func HandleParlError(fn func(), storeError func(err error))
HandleParlError recovers from panic in fn invoking an error callback. HandleParlError is deferable storeError can be the thread-safe perrors.ParlError.AddErrorProc()
func NoOnError ¶
func NoOnError(err error)
NoOnError is used with Recover to silence the default error logging
func Recover ¶
Recover recovers from a panic invoking a function no more than once. If there is *errp does not hold an error and there is no panic, onError is not invoked. Otherwise, onError is invoked exactly once. *errp is updated with a possible panic.
func Recover2 ¶
Recover2 recovers from a panic and may invoke onError multiple times. onError is invoked if there is an error at *errp and on a possible panic. *errp is updated with a possible panic.
func RecoverInvocationPanic ¶
func RecoverInvocationPanic(fn func(), errp *error)
RecoverInvocationPanic is intended to wrap callback invocations in the callee in order to recover from panics in the callback function. when an error occurs, perrors.AppendError appends the callback error to *errp. if fn is nil, a recovered panic results. if errp is nil, a panic is thrown, can be check with:
if errors.Is(err, ErrErrpNil) …