pantoerr

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package pantoerr (panic to error) provides methods that wrap functionality and recover from panics returing errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRecoveredPanicCause

func GetRecoveredPanicCause(err error) interface{}

func IsRecoveredPanic

func IsRecoveredPanic(err error) bool

func PanicToError

func PanicToError(errMsg string, f func() error) error

Runs the function given, recovering from any panics and returning a RecoveredPanic error with the errMsg given. The function can optionally return an error of its own, which will be returned in the non-panic case.

func PanicToErrorInstance

func PanicToErrorInstance(errInstance error, f func() error) error

Runs the function given, recovering from any panics and returning the given error instance instead. The function can optionally return an error of its own, which will be returned in the non-panic case.

func PanicToErrorNil

func PanicToErrorNil(errMsg string, f func()) error

Same as PanicToError, but for functions that don't return errors except in the case of panic.

Types

type RecoveredPanic

type RecoveredPanic struct {
	PanicCause interface{}
	ErrMsg     string
}

RecoverPanic is used to convert panics to errors. The attic-labs noms codebase loves to panic. This is not idiomatic for Go code. RecoverPanic wraps the cause of the panic retrieved from the recover call, and implements the error interface so it can be treated like a standard error.

func (*RecoveredPanic) Error

func (rp *RecoveredPanic) Error() string

Error returns the error message

Jump to

Keyboard shortcuts

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