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 EndCallbacks(err error) (err2 error)
- 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 NilValueError(err error) (err2 error)
- 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 = EndCallbacks(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 depends on the callback-invoking implementation used.
Usage:
if errors.Is(err, parl.ErrEndCallbacks) { …
var ErrErrpNil = NilValueError(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, parl.ErrNilValue) …
var ErrNilValue = NilValueError(errors.New("end callbacks error"))
ErrNilValue indicates that a panic was caused by a value such as a function argument was nil that cannot be nil.
Usage:
if errors.Is(err, parl.ErrNilValue) { …
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 EndCallbacks ¶ added in v0.4.46
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 NilValueError ¶ added in v0.4.46
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, parl.ErrNilValue) …