Documentation ¶
Overview ¶
Package errf provides declarative error handling for Go.
Basic usage ¶
Each use of errorflow has a scope of a single function.
If function uses errorflow its first statement should be IfError() handler configuration:
func exampleFunction() (err error) { defer errf.IfError().ReturnFirst().LogIfSuppressed().ThenAssignTo(&err) // ... business logic ... }
Default configuration is to return first error and never log errors.
defer errf.IfError().ThenAssignTo(&err) /* same as */ defer errf.IfError().ReturnFirst().LogNever().ThenAssignTo(&err)
IfError() handler should always be terminated by one of Then*() functions.
Then, when function has IfError() handler setup, all error checks should be done via one of Check* functions:
func exampleFunction() (err error) { defer errf.IfError().ThenAssignTo(&err) // Just checking err. err := someFunction1() errf.CheckErr(err) /* same as */ errf.CheckErr(someFunction1()) // Checking err, discarding return value. _, err := someFunction2() errf.CheckErr(err) /* same as */ errf.CheckDiscard(someFunction2()) // Checking err using return value (untyped). var value interface{} value, err = someFunction3() errf.CheckErr(err) typedValue := value.(type) /* same as */ typedValue := errf.CheckAny(someFunction3()).(type) // NOTE: using CheckAny is not recommended, // clients should prefer using either standard typed function // or create custom ones (see 'Extending errorflow for custom types' below). // Checking err using return value (typed). int64Value, err := someFunction4() errf.CheckErr(err) /* same as */ int64Value := errf.Std.CheckInt64(someFunction4()) /* same as */ int64Value, err := errf.Std.CheckInt64Err(someFunction4()) // It is not recommended to manually return errors (return fmt.Errorf(...)) // or assign errors (err = fmt.Errorf(...)) for functions with IfError() handler. // In such cases, wrap error in errf.CheckErr(...) to make sure it is handled // by IfError() handler. return errf.CheckErr(someFunction5()).IfOkReturnNil }
When any of Check* functions encounters an error, it immediately sends a program flow control to IfError() handler, unwinding stack of already registered 'defers'. Internally it uses panic to accomplish this goal.
Never use Check* functions in functions without IfError() handler set up (including nested anonymous functions).
Usage correctness validation ¶
When running Go tests, errorflow automatically verifies correctness of errorflow usage and panics with message "errflow incorrect call sequence" when the issue is detected. Stacktrace will point to the location of the issue.
Validation automatically checks for these rules:
- If any of Check* functions is used in a function, IfError() handler should be set up for this function.
- If IfError() handler is set up, it should be terminated by one of Then* functions.
By default, validation is only enabled in tests and is disabled in production binaries.
To enable/disable validation (e.g. because of performance issues, false positives, incorrect test/prod environment detection), clients can use SetNoopValidator or SetStackTraceValidator functions.
func Test_WithDisabledValidator(t *testing.T) { defer errf.SetNoopValidator().ThenRestore() // Validator will be disabled until the end of this function. }
Return Strategy ¶
Return strategy controls what error to return from a function in case if multiple errors were produced (e.g. by gzipWriter.Close() function and then fileWriter.Close() function).
Return strategy is set by using one of Return* functions from IfError() handler.
Available strategies:
- ReturnFirst() - return first encountered error.
- ReturnLast() - return last encountered error.
- ReturnWrapped() - return error where:
- error message combines both messages;
- first error instance is available via errors.Unwrap();
- second error instance instance is discarded.
- ReturnCombined() - return error where:
- error message combines both messages;
- all error instances are available via errf.GetCombinedErrors() function.
Example:
func example() (err error) { defer errf.IfError().Return*().ThenAssignTo(&err) defer errf.CheckErr(fmt.Errorf("error 3")) defer errf.CheckErr(fmt.Errorf("error 2")) defer errf.CheckErr(fmt.Errorf("error 1")) return nil } Results: * ReturnFirst -> "error 1" * ReturnLast -> "error 3" * ReturnWrapped -> "error 1 (also: error 2) (also: error 3)" errors.Unwrap(err).Error() == "error 1" * ReturnCombined -> "combined error {error 1; error 2; error 3}" errf.GetCombinedErrors(err) -> {fmt.Errorf("error 1"), fmt.Errorf("error 2"), fmt.Errorf("error 3")}
Log Strategy ¶
Log strategy controls IfError() handler logging behavior.
Available strategies:
- LogNever() - never log errors.
- LogIfSuppressed() - log only errors which are not included in result.
- LogAlways() - log all errors.
Example:
func example() (err error) { defer errf.IfError().ReturnFirst().Log*().ThenAssignTo(&err) defer errf.CheckErr(fmt.Errorf("error 2")) defer errf.CheckErr(fmt.Errorf("error 1")) return nil } Results: * LogNever -> no logs * LogIfSuppressed -> "error 2" is logged * LogAlways -> both "error 1" and "error 2" are logged
Wrappers ¶
Wrappers are functions which wrap error objects into other error objects.
They can be applied to:
- individual Check* functions example: errf.With(wrapper).CheckErr(err)
- IfError() helper example: defer errf.IfError().Apply(wrapper).ThenAssignTo(&err)
- helper functions (errf.Log, errf.IfErrorAssignTo) example: defer errf.With(wrapper).Log(err)
Example:
func example() (err error) { defer errf.IfError().Apply(errf.WrapperFmtErrorw("wrapped")).ThenAssignTo(&err) return errf.CheckErr(fmt.Errorf("error")) } Returns error with message: "wrapped: error"
Custom wrappers can be implemented using errf.Wrapper function:
func addStacktraceToError(err error) error { /* ... actual implementation ... */ } var WrapperAddStacktrace = func(ef *Errflow) *Errflow { return ef.With(errf.Wrapper(addStacktraceToError)) }
Usage:
func example() (err error) { defer errf.IfError().Apply(WrapperAddStacktrace).ThenAssignTo(&err) // business logic ... }
Handlers ¶
Handlers are used to handle errors and panics that are bubbling up the defers ladder.
Unlike IfError()... handler, Handle() API can be used in a middle of the function, thus e.g. skipped if preparation steps haven't been executed yet.
This might be useful for additional cleanup logic. Consider function that copies files. If there is an error during copying, we would want to delete destination file rather than leaving it in inconsistent state. But, unlike closing a file, this action needs to be performed only when there's an error and should not be performed on a successful copy.
Here's how handlers can be used to implement this logic:
func copyfile(src, dst string) (err error) { defer errf.IfError().ThenAssignTo(&err) /* some code */ writer := errf.Io.WriteCloser(os.Create(filename)) defer errf.Handle().OnAnyErrorOrPanic(func() { os.Remove(filename) }) defer errf.CheckDeferErr(writer.Close) /* more code */ }
For full list of handlers, see documentation for:
- (*InterimHandler) On* methods
- (*InterimHandler) {Always, Everything} methods
Notes:
- Handle() API should be used only in defer statements.
- Handlers with "Err" in the name (e.g. OnErr, OnErrOrPanic) can only be used in functions with IfError() handler.
- Handlers without "Err" in the name (e.g. Always, OnPanic) can be used in any function.
- It is allowed to use Check* funcions inside Handlers even without IfError() set up inside a handler. In such cases, defer Handle()... enclosing function IfError() will be used to catch errors.
Custom log function ¶
Custom log function can be set using SetLogFn method:
func customLogFn(logMessage *LogMessage) { /* ... implementation ... */ } func main() { defer errf.SetLogFn(customLogFn).ThenRestore() /* app main function */ }
Helper functions ¶
Errflow also implements few helper functions which can be used in functions without IfError() handler.
errf.Log(err) will log error, if not nil. It doesn't affect control flow. defer errf.IfErrorThenAssign(&err, operationErr) will assign (*err = operationErr) if operationErr != nil. Note: it is useful only in 'defer' for function without IfError() handler as a lightweight alternative.
This functions might be configured using errf.With(...).
NOTE: since these functions don't use IfError() handler, they will not use config defined on IfError() handler.
func example() (err error) { errOpts = errf.WrapperFmtErrorw("error in example function") defer errf.IfError().Apply(errOpts).ThenAssignTo(&err) errf.With(errOpts).Log(fmt.Errorf("operation 1 error")) return errf.CheckErr(fmt.Errorf("operation 2 error")) } This function will return error "error in example function: operation 2 error". Also it will log "error in example function: operation 1 error". Note that Log requires .With(errOpts), because it won't use IfError() context.
Extending errorflow for custom types ¶
Library clients can create new Check* functions for custom return types. This is useful for writing type safe code (until generics will solve this problem).
Example:
package fancypackage var Errf = FancyPackageErrflow{} type FancyPackageErrflow struct { errflow *Errflow } func (ef FancyPackageErrflow) With(options ...ErrflowOption) FancyPackageErrflow { return FancyPackageErrflow{errflow: ef.errflow.With(options...)} } func (ef FancyPackageErrflow) CheckCustomType1(value *CustomType1, err error) *CustomType1 { ef.errflow.ImplementCheck(recover(), err) return value } func (ef FancyPackageErrflow) CheckCustomType2(value *CustomType2, err error) *CustomType2 { ef.errflow.ImplementCheck(recover(), err) return value } package main func ProcessCustomStruct() (err error) { defer errflow.IfError().ThenAssignTo(&err) customStructValue := fancypackage.Errf.CheckCustomType1(fancypackage.ReadCustomType1()) customStructValue := fancypackage.Errf. With(errf.WrapperFmtErrorw("error in ProcessCustomStruct")). CheckCustomType2(fancypackage.ReadCustomType2()) // ... }
Index ¶
- Variables
- func CheckAny(value interface{}, err error) interface{}
- func GetCombinedErrors(err error) []error
- func GetPanic(err error, panicObj *interface{}) bool
- func IfErrorAssignTo(outErr *error, closeFn func() error)
- func IsErr(err error) bool
- func IsPanic(err error) bool
- func IsSuccess(err error) bool
- func Log(err error)
- func LogDefer(closeFn func() error)
- type BufioErrflow
- func (ef BufioErrflow) CheckReadWriter(value *bufio.ReadWriter, err error) *bufio.ReadWriter
- func (ef BufioErrflow) CheckReadWriterErr(value *bufio.ReadWriter, err error) (*bufio.ReadWriter, error)
- func (ef BufioErrflow) CheckReader(value *bufio.Reader, err error) *bufio.Reader
- func (ef BufioErrflow) CheckReaderErr(value *bufio.Reader, err error) (*bufio.Reader, error)
- func (ef BufioErrflow) CheckWriter(value *bufio.Writer, err error) *bufio.Writer
- func (ef BufioErrflow) CheckWriterErr(value *bufio.Writer, err error) (*bufio.Writer, error)
- func (ef BufioErrflow) With(options ...ErrflowOption) BufioErrflow
- type CheckResult
- func CheckAssert(condition bool, format string, a ...interface{}) CheckResult
- func CheckCondition(condition bool, format string, a ...interface{}) CheckResult
- func CheckDeferErr(closeFn func() error) CheckResult
- func CheckDiscard(_ interface{}, err error) CheckResult
- func CheckErr(err error) CheckResult
- type CombinedError
- type DeferRestorer
- type Errflow
- func LogStrategyAlways(ef *Errflow) *Errflow
- func LogStrategyIfSuppressed(ef *Errflow) *Errflow
- func LogStrategyNever(ef *Errflow) *Errflow
- func ReturnStrategyCombined(ef *Errflow) *Errflow
- func ReturnStrategyFirst(ef *Errflow) *Errflow
- func ReturnStrategyLast(ef *Errflow) *Errflow
- func ReturnStrategyWrapped(ef *Errflow) *Errflow
- func With(options ...ErrflowOption) *Errflow
- func (ef *Errflow) AsOpts() ErrflowOption
- func (ef *Errflow) CheckAny(value interface{}, err error) interface{}
- func (ef *Errflow) CheckAssert(condition bool, format string, a ...interface{}) CheckResult
- func (ef *Errflow) CheckCondition(condition bool, format string, a ...interface{}) CheckResult
- func (ef *Errflow) CheckDeferErr(closeFn func() error) CheckResult
- func (ef *Errflow) CheckDiscard(_ interface{}, err error) CheckResult
- func (ef *Errflow) CheckErr(err error) CheckResult
- func (ef *Errflow) IfErrorAssignTo(outErr *error, closeFn func() error)
- func (ef *Errflow) ImplementCheck(recoverObj interface{}, err error) CheckResult
- func (ef *Errflow) Log(err error)
- func (ef *Errflow) LogDefer(closeFn func() error)
- func (ef *Errflow) Opts() []ErrflowOption
- func (ef *Errflow) With(options ...ErrflowOption) *Errflow
- type ErrflowOption
- type ErrorActionFn
- type IfErrorHandler
- func (c *IfErrorHandler) Apply(options ...ErrflowOption) *IfErrorHandler
- func (c *IfErrorHandler) LogAlways() *IfErrorHandler
- func (c *IfErrorHandler) LogIfSuppressed() *IfErrorHandler
- func (c *IfErrorHandler) LogNever() *IfErrorHandler
- func (c *IfErrorHandler) ReturnCombined() *IfErrorHandler
- func (c *IfErrorHandler) ReturnFirst() *IfErrorHandler
- func (c *IfErrorHandler) ReturnLast() *IfErrorHandler
- func (c *IfErrorHandler) ReturnWrapped() *IfErrorHandler
- func (c *IfErrorHandler) Then(fns ...ErrorActionFn)
- func (c *IfErrorHandler) ThenAssignTo(outErr *error)
- func (c *IfErrorHandler) ThenIgnore()
- type InterimHandler
- func (h *InterimHandler) Always(errFn func())
- func (h *InterimHandler) Everything(errFn ErrorActionFn)
- func (h *InterimHandler) OnAnyErr(errFn func())
- func (h *InterimHandler) OnAnyErrOrPanic(errFn func())
- func (h *InterimHandler) OnAnyPanic(panicFn func())
- func (h *InterimHandler) OnErr(errFn ErrorActionFn)
- func (h *InterimHandler) OnErrAs(errFn interface{})
- func (h *InterimHandler) OnErrIs(targetErr error, errFn func())
- func (h *InterimHandler) OnErrOrPanic(errFn ErrorActionFn)
- func (h *InterimHandler) OnPanic(panicFn func(panicObj interface{}))
- func (h *InterimHandler) OnSuccess(successFn func())
- type IoErrflow
- func (ef IoErrflow) CheckReadCloser(value io.ReadCloser, err error) io.ReadCloser
- func (ef IoErrflow) CheckReadCloserErr(value io.ReadCloser, err error) (io.ReadCloser, error)
- func (ef IoErrflow) CheckReader(value io.Reader, err error) io.Reader
- func (ef IoErrflow) CheckReaderErr(value io.Reader, err error) (io.Reader, error)
- func (ef IoErrflow) CheckWriteCloser(value io.WriteCloser, err error) io.WriteCloser
- func (ef IoErrflow) CheckWriteCloserErr(value io.WriteCloser, err error) (io.WriteCloser, error)
- func (ef IoErrflow) CheckWriter(value io.Writer, err error) io.Writer
- func (ef IoErrflow) CheckWriterErr(value io.Writer, err error) (io.Writer, error)
- func (ef IoErrflow) With(options ...ErrflowOption) IoErrflow
- type LogFn
- type LogMessage
- type OsErrflow
- type PanicErr
- type StdErrflow
- func (ef StdErrflow) CheckBool(value bool, err error) bool
- func (ef StdErrflow) CheckBoolErr(value bool, err error) (bool, error)
- func (ef StdErrflow) CheckBoolSlice(value []bool, err error) []bool
- func (ef StdErrflow) CheckBoolSliceErr(value []bool, err error) ([]bool, error)
- func (ef StdErrflow) CheckByte(value byte, err error) byte
- func (ef StdErrflow) CheckByteErr(value byte, err error) (byte, error)
- func (ef StdErrflow) CheckByteSlice(value []byte, err error) []byte
- func (ef StdErrflow) CheckByteSliceErr(value []byte, err error) ([]byte, error)
- func (ef StdErrflow) CheckComplex128(value complex128, err error) complex128
- func (ef StdErrflow) CheckComplex128Err(value complex128, err error) (complex128, error)
- func (ef StdErrflow) CheckComplex128Slice(value []complex128, err error) []complex128
- func (ef StdErrflow) CheckComplex128SliceErr(value []complex128, err error) ([]complex128, error)
- func (ef StdErrflow) CheckComplex64(value complex64, err error) complex64
- func (ef StdErrflow) CheckComplex64Err(value complex64, err error) (complex64, error)
- func (ef StdErrflow) CheckComplex64Slice(value []complex64, err error) []complex64
- func (ef StdErrflow) CheckComplex64SliceErr(value []complex64, err error) ([]complex64, error)
- func (ef StdErrflow) CheckFloat32(value float32, err error) float32
- func (ef StdErrflow) CheckFloat32Err(value float32, err error) (float32, error)
- func (ef StdErrflow) CheckFloat32Slice(value []float32, err error) []float32
- func (ef StdErrflow) CheckFloat32SliceErr(value []float32, err error) ([]float32, error)
- func (ef StdErrflow) CheckFloat64(value float64, err error) float64
- func (ef StdErrflow) CheckFloat64Err(value float64, err error) (float64, error)
- func (ef StdErrflow) CheckFloat64Slice(value []float64, err error) []float64
- func (ef StdErrflow) CheckFloat64SliceErr(value []float64, err error) ([]float64, error)
- func (ef StdErrflow) CheckInt(value int, err error) int
- func (ef StdErrflow) CheckInt16(value int16, err error) int16
- func (ef StdErrflow) CheckInt16Err(value int16, err error) (int16, error)
- func (ef StdErrflow) CheckInt16Slice(value []int16, err error) []int16
- func (ef StdErrflow) CheckInt16SliceErr(value []int16, err error) ([]int16, error)
- func (ef StdErrflow) CheckInt32(value int32, err error) int32
- func (ef StdErrflow) CheckInt32Err(value int32, err error) (int32, error)
- func (ef StdErrflow) CheckInt32Slice(value []int32, err error) []int32
- func (ef StdErrflow) CheckInt32SliceErr(value []int32, err error) ([]int32, error)
- func (ef StdErrflow) CheckInt64(value int64, err error) int64
- func (ef StdErrflow) CheckInt64Err(value int64, err error) (int64, error)
- func (ef StdErrflow) CheckInt64Slice(value []int64, err error) []int64
- func (ef StdErrflow) CheckInt64SliceErr(value []int64, err error) ([]int64, error)
- func (ef StdErrflow) CheckInt8(value int8, err error) int8
- func (ef StdErrflow) CheckInt8Err(value int8, err error) (int8, error)
- func (ef StdErrflow) CheckInt8Slice(value []int8, err error) []int8
- func (ef StdErrflow) CheckInt8SliceErr(value []int8, err error) ([]int8, error)
- func (ef StdErrflow) CheckIntErr(value int, err error) (int, error)
- func (ef StdErrflow) CheckIntSlice(value []int, err error) []int
- func (ef StdErrflow) CheckIntSliceErr(value []int, err error) ([]int, error)
- func (ef StdErrflow) CheckRune(value rune, err error) rune
- func (ef StdErrflow) CheckRuneErr(value rune, err error) (rune, error)
- func (ef StdErrflow) CheckRuneSlice(value []rune, err error) []rune
- func (ef StdErrflow) CheckRuneSliceErr(value []rune, err error) ([]rune, error)
- func (ef StdErrflow) CheckString(value string, err error) string
- func (ef StdErrflow) CheckStringErr(value string, err error) (string, error)
- func (ef StdErrflow) CheckStringSlice(value []string, err error) []string
- func (ef StdErrflow) CheckStringSliceErr(value []string, err error) ([]string, error)
- func (ef StdErrflow) CheckUint(value uint, err error) uint
- func (ef StdErrflow) CheckUint16(value uint16, err error) uint16
- func (ef StdErrflow) CheckUint16Err(value uint16, err error) (uint16, error)
- func (ef StdErrflow) CheckUint16Slice(value []uint16, err error) []uint16
- func (ef StdErrflow) CheckUint16SliceErr(value []uint16, err error) ([]uint16, error)
- func (ef StdErrflow) CheckUint32(value uint32, err error) uint32
- func (ef StdErrflow) CheckUint32Err(value uint32, err error) (uint32, error)
- func (ef StdErrflow) CheckUint32Slice(value []uint32, err error) []uint32
- func (ef StdErrflow) CheckUint32SliceErr(value []uint32, err error) ([]uint32, error)
- func (ef StdErrflow) CheckUint64(value uint64, err error) uint64
- func (ef StdErrflow) CheckUint64Err(value uint64, err error) (uint64, error)
- func (ef StdErrflow) CheckUint64Slice(value []uint64, err error) []uint64
- func (ef StdErrflow) CheckUint64SliceErr(value []uint64, err error) ([]uint64, error)
- func (ef StdErrflow) CheckUint8(value uint8, err error) uint8
- func (ef StdErrflow) CheckUint8Err(value uint8, err error) (uint8, error)
- func (ef StdErrflow) CheckUint8Slice(value []uint8, err error) []uint8
- func (ef StdErrflow) CheckUint8SliceErr(value []uint8, err error) ([]uint8, error)
- func (ef StdErrflow) CheckUintErr(value uint, err error) (uint, error)
- func (ef StdErrflow) CheckUintSlice(value []uint, err error) []uint
- func (ef StdErrflow) CheckUintSliceErr(value []uint, err error) ([]uint, error)
- func (ef StdErrflow) CheckUintptr(value uintptr, err error) uintptr
- func (ef StdErrflow) CheckUintptrErr(value uintptr, err error) (uintptr, error)
- func (ef StdErrflow) CheckUintptrSlice(value []uintptr, err error) []uintptr
- func (ef StdErrflow) CheckUintptrSliceErr(value []uintptr, err error) ([]uintptr, error)
- func (ef StdErrflow) With(options ...ErrflowOption) StdErrflow
Constants ¶
This section is empty.
Variables ¶
var Bufio = BufioErrflow{}
Bufio contains collection of Check* functions for bufio.* types.
var DefaultErrflow = &Errflow{}
DefaultErrflow is default Errflow instance. Clients should never set its value.
var Io = IoErrflow{}
Io contains collection of Check* functions for io.* types.
var OriginalErr = &originalErrType{}
OriginalErr is a placeholder for error in WrapperFmtErrorf(...) call.
var Os = OsErrflow{}
Os contains collection of Check* functions for os.* types.
var Std = StdErrflow{}
Std contains collection of Check* functions for built-in types.
Functions ¶
func CheckAny ¶
func CheckAny(value interface{}, err error) interface{}
CheckAny is an alias for DefaultErrflow.CheckAny(...).
func GetCombinedErrors ¶
GetCombinedErrors returns all error instances from CombinedError error, even if the error was wrapped using fmt.Errorf with "%w" parameter.
Note that resulting errors are all flattened out into a single list, meaning that calling GetCombinedErrors on errors returned from GetCombinedErrors will always result in returning the same error.
func GetPanic ¶ added in v0.2.0
GetPanic returns true when error send to handler callback indicates a panic (not error or success). Also it writes panic value into panicObj pointer.
func IfErrorAssignTo ¶
IfErrorAssignTo is an alias for DefaultErrflow.IfErrorAssignTo(...).
func IsErr ¶ added in v0.2.0
IsErr returns true when error send to handler callback indicates an error (not panic or success). Useful for handlers which handle multiple types (e.g. Everything(), OnErrOrPanic())
func IsPanic ¶ added in v0.2.0
IsPanic returns true when error send to handler callback indicates a panic (not error or success). Useful for handlers which handle multiple types (e.g. Everything(), OnErrOrPanic())
Types ¶
type BufioErrflow ¶
type BufioErrflow struct {
// contains filtered or unexported fields
}
BufioErrflow implements Check* functions for bufio package types.
Clients should not instantiate BufioErrflow, use 'errf.Bufio' instead.
func (BufioErrflow) CheckReadWriter ¶
func (ef BufioErrflow) CheckReadWriter(value *bufio.ReadWriter, err error) *bufio.ReadWriter
CheckReadWriter calls errflow.Check and returns a typed value from a function call.
func (BufioErrflow) CheckReadWriterErr ¶
func (ef BufioErrflow) CheckReadWriterErr(value *bufio.ReadWriter, err error) (*bufio.ReadWriter, error)
CheckReadWriterErr calls errflow.Check and returns a typed value and error from a function call.
func (BufioErrflow) CheckReader ¶
CheckReader calls errflow.Check and returns a typed value from a function call.
func (BufioErrflow) CheckReaderErr ¶
CheckReaderErr calls errflow.Check and returns a typed value and error from a function call.
func (BufioErrflow) CheckWriter ¶
CheckWriter calls errflow.Check and returns a typed value from a function call.
func (BufioErrflow) CheckWriterErr ¶
CheckWriterErr calls errflow.Check and returns a typed value and error from a function call.
func (BufioErrflow) With ¶
func (ef BufioErrflow) With(options ...ErrflowOption) BufioErrflow
With implements Errflow.With(...) for bufio types.
type CheckResult ¶ added in v0.4.0
type CheckResult struct {
IfOkReturnNil error
}
CheckResult default object is returned by Check* functions which don't return any value, as a helper for return statements:
return errf.CheckErr(err).IfOkReturnNil
func CheckAssert ¶ added in v0.4.0
func CheckAssert(condition bool, format string, a ...interface{}) CheckResult
CheckAssert is an alias for DefaultErrflow.CheckAssert(...).
func CheckCondition ¶
func CheckCondition(condition bool, format string, a ...interface{}) CheckResult
CheckCondition is an alias for DefaultErrflow.CheckCondition(...).
func CheckDeferErr ¶ added in v0.3.0
func CheckDeferErr(closeFn func() error) CheckResult
CheckDeferErr is an alias for DefaultErrflow.CheckDeferErr(...).
func CheckDiscard ¶
func CheckDiscard(_ interface{}, err error) CheckResult
CheckDiscard is an alias for DefaultErrflow.CheckDiscard(...).
func CheckErr ¶
func CheckErr(err error) CheckResult
CheckErr is an alias for DefaultErrflow.CheckErr(...).
type CombinedError ¶
type CombinedError struct {
// contains filtered or unexported fields
}
CombinedError implements an error that holds multiple errors.
func (CombinedError) Error ¶
func (cErr CombinedError) Error() string
type DeferRestorer ¶
type DeferRestorer interface { // ThenRestore restores previous global config. // See DeferRestorer comment for example. ThenRestore() }
DeferRestorer is helper interface to update global config in a scope of a single function, typically useful for testing or for main function configuration.
Example:
func Test1(t *testing.Test) { defer SetGlobalConfig(&Config{ param1: "value1", param2: "value2" }).ThenRestore() // ... }
func SetLogFn ¶
func SetLogFn(logFn LogFn) DeferRestorer
SetLogFn replaces logging function for errflow. It returns errf.DeferRestorer instance, which can be used to restore previous logFn, if needed. Default log function is log.Println().
func SetNoopValidator ¶
func SetNoopValidator() DeferRestorer
SetNoopValidator sets no-op validator for errflow.
Validator is used to validate that the library is used correctly, meaning each usage is limited to a single function.
This is a default mode for production, which doesn't compromise performance, but library can be misused in this mode.
It returns errf.DeferRestorer instance, which can be used to restore previous validator, if needed.
func SetStackTraceValidator ¶
func SetStackTraceValidator() DeferRestorer
SetStackTraceValidator sets a stack-trace based validator for errflow.
Validator is used to validate that the library is used correctly, meaning each usage is limited to a single function.
This is a default mode for tests, which works in most cases, but has performance penalty and might return false positives in some cases.
It returns errf.DeferRestorer instance, which can be used to restore previous validator, if needed.
type Errflow ¶
type Errflow struct {
// contains filtered or unexported fields
}
Errflow contains configuration for error handling logic. It exposes an immutable API for clients, but it is not thread-safe.
func LogStrategyAlways ¶
LogStrategyAlways configures Errflow instance to always log errors.
func LogStrategyIfSuppressed ¶
LogStrategyIfSuppressed configures Errflow instance to log errors only if they are not present in resulting error value.
func LogStrategyNever ¶
LogStrategyNever configures Errflow instance to never log errors. This is default behavior.
func ReturnStrategyCombined ¶
ReturnStrategyCombined configures Errflow instance to return all errors. All error messages will be collected in resulting message and all error instances will be preserved. Error instances can be retrieved using GetCombinedErrors() function.
func ReturnStrategyFirst ¶
ReturnStrategyFirst configures Errflow instance to return first error instance. This is default behavior.
func ReturnStrategyLast ¶
ReturnStrategyLast configures Errflow instance to return last error instance.
func ReturnStrategyWrapped ¶
ReturnStrategyWrapped configures Errflow instance to return all errors. First error will be wrapped using fmt.Errorf with "%w" parameter. For other error, their messages will be included in resulting errors, but the instances will be discarded.
func With ¶
func With(options ...ErrflowOption) *Errflow
With is an alias for DefaultErrflow.With(...).
func (*Errflow) AsOpts ¶ added in v0.2.0
func (ef *Errflow) AsOpts() ErrflowOption
AsOpts returns ErrflowOption copies all configs of Errflow.
func (*Errflow) CheckAny ¶
CheckAny sends error to IfError() handler for processing, if there is an error. If there is no error, it returns value as a generic interface{}.
Example:
function ProcessFile() (err error) { defer errf.IfError().ThenAssignTo(&err) file := errf.CheckAny(os.Create("file.go")).(*os.File) defer errf.CheckDeferErr(file.Close) // Write to file ... }
Tip: prefer using typed functions, defined in either this library, or custom ones, implemented using errf.ImplementCheck(...).
Example above can usually rewritten as:
function ProcessFile() (err error) { defer errf.IfError().ThenAssignTo(&err) writer := errf.Io.CheckWriteCloser(os.Create("file.go")) defer errf.CheckDeferErr(writer.Close) // Write to file ... }
func (*Errflow) CheckAssert ¶ added in v0.4.0
func (ef *Errflow) CheckAssert(condition bool, format string, a ...interface{}) CheckResult
CheckAssert creates and sends error to IfError() handler for processing, if condition is false.
func (*Errflow) CheckCondition ¶
func (ef *Errflow) CheckCondition(condition bool, format string, a ...interface{}) CheckResult
CheckCondition creates and sends error to IfError() handler for processing, if condition is true.
func (*Errflow) CheckDeferErr ¶ added in v0.3.0
func (ef *Errflow) CheckDeferErr(closeFn func() error) CheckResult
CheckDeferErr calls closeFn and checks for return error. Useful in defer statements:
writer := ... defer errf.CheckDeferErr(writer.Close)
func (*Errflow) CheckDiscard ¶
func (ef *Errflow) CheckDiscard(_ interface{}, err error) CheckResult
CheckDiscard sends error to IfError() handler for processing, if there is an error. Non-error value returned from a function is discarded.
Example:
function writeBuf(w io.Writer, buf []byte) (err error) { defer errf.IfError().ThenAssignTo(&err) return errf.CheckDiscard(w.Write(buf)) }
func (*Errflow) CheckErr ¶
func (ef *Errflow) CheckErr(err error) CheckResult
CheckErr sends error to IfError() handler for processing, if there is an error.
It is required that 'defer errf.IfError().Then...' is configured in the same function as CheckErr, otherwise validation will fail when running tests.
CheckErr always returns nil, but type system allows using it to skip return nil statement:
errflow.CheckErr(functionCall()) return nil
is the same as:
return errflow.CheckErr(functionCall())
func (*Errflow) IfErrorAssignTo ¶
IfErrorAssignTo is a helper method to set function return error value in defer calls. It is useful in functions that don't use 'defer errf.IfError()...' handlers. It is possible to use most of errf.With(...) configs. Unsupported configs (e.g. ReturnStrategyLast) will panic when used.
Note: don't mix IfErrorAssignTo with 'defer errf.IfError()...' and Check* functions in the same function. They are not designed to work together.
Example:
func example() (err error) { writer, err := openWriter(...) defer errf.With( errf.LogStrategyIfSuppressed, ).IfErrorAssignTo(&err, writer.Close) // ... }
func (*Errflow) ImplementCheck ¶
func (ef *Errflow) ImplementCheck(recoverObj interface{}, err error) CheckResult
ImplementCheck is used to implement a strongly-typed errflow.Check(...) for new types.
Example:
package fancypackage var Errf = FancyPackageErrflow{} type FancyPackageErrflow struct { errflow *Errflow } func (ef FancyPackageErrflow) With(options ...ErrflowOption) FancyPackageErrflow { return FancyPackageErrflow{errflow: ef.errflow.With(options...)} } func (ef FancyPackageErrflow) CheckCustomType1(value *CustomType1, err error) *CustomType1 { ef.errflow.ImplementCheck(recover(), err) return value } func (ef FancyPackageErrflow) CheckCustomType2(value *CustomType2, err error) *CustomType2 { ef.errflow.ImplementCheck(recover(), err) return value } package main func ProcessCustomStruct() (err error) { defer errflow.IfError().ThenAssignTo(&err) customStructValue := fancypackage.Errf.CheckCustomType1( fancypackage.ReadCustomType1()) // ... }
func (*Errflow) Log ¶
Log logs error, if not nil. Always logs, even if log strategy is LogStrategyNever. Doesn't affect control flow.
func (*Errflow) LogDefer ¶ added in v0.3.0
LogDefer calls closeFn, then calls Log(...) on result of a call. Useful in defer statements:
reader := ... defer errf.LogDefer(reader.Close)
func (*Errflow) Opts ¶
func (ef *Errflow) Opts() []ErrflowOption
Opts returns all options, which were applied on top of DefaultErrflow instance.
func (*Errflow) With ¶
func (ef *Errflow) With(options ...ErrflowOption) *Errflow
With adds additional configs to Errflow instance. It returns a new instance. Original instance is unmodified.
type ErrflowOption ¶
ErrflowOption is used for extending config API. Clients can extend config API with new methods by implementing ErrflowOption.
Example:
func WrapInOurError(ef *Errflow) *Errflow { return ef.With(errf.Wrapper(func (err error) error { return ourerrors.Wrap(err) })) } func exampleUsage() (err error) { defer errf.IfError().Apply(WrapInOurError).ThenAssignTo(&err) // ... }
func Opts ¶
func Opts(options ...ErrflowOption) ErrflowOption
Opts combines multiple options into a single.
func OptsFrom ¶
func OptsFrom(ef *Errflow) ErrflowOption
OptsFrom creates ErrflowOption which applies all options from provided Errflow.
func Wrapper ¶
func Wrapper(wrapper func(err error) error) ErrflowOption
Wrapper function creates ErrflowOption that wraps original errors using provided 'func(err error) error' function.
See WrapperFmtErrorw for common scenario fmt.Errorf("wrap message: %w", err).
Example:
func WrapInOurError(ef *Errflow) *Errflow { return ef.With(errf.Wrapper(func (err error) error { return ourerrors.Wrap(err) })) } func exampleUsage() (err error) { defer errf.IfError().Apply(WrapInOurError).ThenAssignTo(&err) // ... }
func WrapperFmtErrorf ¶
func WrapperFmtErrorf(format string, a ...interface{}) ErrflowOption
WrapperFmtErrorf is a Wrapper that uses fmt.Errorf to wrap errors. errf.OriginalErr is used as a placeholder for error in fmt.Errorf args.
See WrapperFmtErrorw for common scenario fmt.Errorf("wrap message: %w", err).
Example:
func exampleUsage() (err error) { defer errf.IfError().Apply( errf.WrapperFmtErrorf("%s %w %s", "-->", errf.OriginalErr, "<--") ).ThenAssignTo(&err) // ... }
func WrapperFmtErrorw ¶
func WrapperFmtErrorw(s string) ErrflowOption
WrapperFmtErrorw is a Wrapper that uses fmt.Errorf("%s: %w", ...) to wrap errors.
Example:
func exampleUsage() (err error) { defer errf.IfError().Apply(errf.WrapperFmtErrorw("error in exampleUsage")).ThenAssignTo(&err) // ... }
type ErrorActionFn ¶ added in v0.2.0
type ErrorActionFn func(err error)
ErrorActionFn is a callback for errors handlers.
type IfErrorHandler ¶
type IfErrorHandler struct {
// contains filtered or unexported fields
}
IfErrorHandler configures errorflow error handling behavior in a scope of a function.
Should be created only via IfError() method.
func IfError ¶
func IfError() *IfErrorHandler
IfError creates IfErrorHandler.
Should always:
- be used only in defer statements;
- be in the beginning of a function;
- terminated by one of Then*(...) functions.
Example:
function example() (err error) { defer errf.IfError().ThenAssignTo(&err) // ... }
func (*IfErrorHandler) Apply ¶
func (c *IfErrorHandler) Apply(options ...ErrflowOption) *IfErrorHandler
Apply configures IfErrorHandler to apply additional configs to Errflow.
Example:
func example() (err error) { defer errf.IfError().Apply(errf.WrapperFmtErrorw("wrapper 2")).ThenAssignTo(&err) With(errf.WrapperFmtErrorw("wrapper 1")).CheckErr(fmt.Errorf("error 1")) return nil }
When example() is called, "wrapper 1" will be applied first and "wrapper 2" will be applied second.
Resulting error message is: "wrapper 2: wrapper 1: error 1".
func (*IfErrorHandler) LogAlways ¶
func (c *IfErrorHandler) LogAlways() *IfErrorHandler
LogAlways is an alias for Apply(LogStrategyAlways).
func (*IfErrorHandler) LogIfSuppressed ¶
func (c *IfErrorHandler) LogIfSuppressed() *IfErrorHandler
LogIfSuppressed is an alias for Apply(LogStrategyIfSuppressed).
func (*IfErrorHandler) LogNever ¶
func (c *IfErrorHandler) LogNever() *IfErrorHandler
LogNever is an alias for Apply(LogStrategyNever).
func (*IfErrorHandler) ReturnCombined ¶
func (c *IfErrorHandler) ReturnCombined() *IfErrorHandler
ReturnCombined is an alias for Apply(ReturnStrategyCombined).
func (*IfErrorHandler) ReturnFirst ¶
func (c *IfErrorHandler) ReturnFirst() *IfErrorHandler
ReturnFirst is an alias for Apply(ReturnStrategyFirst).
func (*IfErrorHandler) ReturnLast ¶
func (c *IfErrorHandler) ReturnLast() *IfErrorHandler
ReturnLast is an alias for Apply(ReturnStrategyLast).
func (*IfErrorHandler) ReturnWrapped ¶
func (c *IfErrorHandler) ReturnWrapped() *IfErrorHandler
ReturnWrapped is an alias for Apply(ReturnStrategyWrapped).
func (*IfErrorHandler) Then ¶
func (c *IfErrorHandler) Then(fns ...ErrorActionFn)
Then calls callbacks for resulting error (only if non-nil).
func (*IfErrorHandler) ThenAssignTo ¶
func (c *IfErrorHandler) ThenAssignTo(outErr *error)
ThenAssignTo assigns resulting error to outErr (only if non-nil). If outErr is already non-nil, it will be replaced by error returned from IfErrorHandler, and logged if log strategy is IfSuppressed or Always.
Note: it is not recommended to mix returning errors directly and via Check* function because IfError handler doesn't have much control over direct errors, which might result in counterintuitive behavior.
To avoid mixing, always instead of:
return err
write
return errf.CheckErr(err).IfOkReturnNil
func (*IfErrorHandler) ThenIgnore ¶
func (c *IfErrorHandler) ThenIgnore()
ThenIgnore ignores resulting error.
type InterimHandler ¶ added in v0.2.0
type InterimHandler struct{}
InterimHandler defines Handle() API.
func Handle ¶ added in v0.2.0
func Handle() *InterimHandler
Handle enables additional error handlers in the middle of functions, in addition to IfError() handlers.
Notes:
- Handle() API should be used only in defer statements.
- Handlers with "Err" in the name (e.g. OnErr, OnErrOrPanic) can only be used in functions with IfError() handler.
- Handlers without "Err" in the name (e.g. Always, OnPanic) can be used in any function.
- It is allowed to use Check* functions inside Handlers even without IfError() set up inside a handler. In such cases, defer Handle()... enclosing function IfError() will be used to catch errors.
Example:
func example(filename string) (err error) { defer errf.IfError().ThenAssignTo(&err) /* some code */ writer := errf.Io.WriteCloser(os.Create(filename)) defer errf.Handle().OnAnyErrorOrPanic(func() { os.Remove(filename) }) defer errf.CheckDeferErr(writer.Close) /* more code */ }
func (*InterimHandler) Always ¶ added in v0.2.0
func (h *InterimHandler) Always(errFn func())
Always handler is always executed. Error is not sent to the callback.
Use Everything(), if error info is required.
func (*InterimHandler) Everything ¶ added in v0.2.0
func (h *InterimHandler) Everything(errFn ErrorActionFn)
Everything handler is always executed. Errors and panics are sent to the callback.
Use IsPanic(), IsErr(), IsSuccess() to differentiate between those outcomes.
Use Always(), if error info is not needed.
func (*InterimHandler) OnAnyErr ¶ added in v0.2.0
func (h *InterimHandler) OnAnyErr(errFn func())
OnAnyErr handler is same as OnErr, when err is not required.
func (*InterimHandler) OnAnyErrOrPanic ¶ added in v0.2.0
func (h *InterimHandler) OnAnyErrOrPanic(errFn func())
OnAnyErrOrPanic handler is same as OnErrOrPanic, when err is not required.
func (*InterimHandler) OnAnyPanic ¶ added in v0.2.0
func (h *InterimHandler) OnAnyPanic(panicFn func())
OnAnyPanic handler is same as OnPanic, when panicObj is not required.
func (*InterimHandler) OnErr ¶ added in v0.2.0
func (h *InterimHandler) OnErr(errFn ErrorActionFn)
OnErr handler is executed in case of error triggered by one of "Check*" functions.
First encountered error is passed to the callback.
func (*InterimHandler) OnErrAs ¶ added in v0.2.0
func (h *InterimHandler) OnErrAs(errFn interface{})
OnErrAs handler is executed in case of error triggered by one of "Check*" functions and first encountered error has type of callback argument (using errors.As definition).
Example:
defer errf.Handle().OnErrAs(func (err net.Error) { // This callback only will be executed if first encountered // error has type of net.Error. })
func (*InterimHandler) OnErrIs ¶ added in v0.2.0
func (h *InterimHandler) OnErrIs(targetErr error, errFn func())
OnErrIs handler is executed in case of error triggered by one of "Check*" functions and first encountered error is targetErr (using errors.Is definition).
func (*InterimHandler) OnErrOrPanic ¶ added in v0.2.0
func (h *InterimHandler) OnErrOrPanic(errFn ErrorActionFn)
OnErrOrPanic handler is executed in case of error triggered by one of "Check*" functions or a panic.
First encountered error is passed to the callback. See also errf.IsPanic(), errf.IsErr().
func (*InterimHandler) OnPanic ¶ added in v0.2.0
func (h *InterimHandler) OnPanic(panicFn func(panicObj interface{}))
OnPanic handler is executed in case of a panic.
func (*InterimHandler) OnSuccess ¶ added in v0.2.0
func (h *InterimHandler) OnSuccess(successFn func())
OnSuccess handler is executed in case of no errors or panics.
type IoErrflow ¶
type IoErrflow struct {
// contains filtered or unexported fields
}
IoErrflow implements Check* functions for io package types.
Clients should not instantiate IoErrflow, use 'errf.Io' instead.
func (IoErrflow) CheckReadCloser ¶
func (ef IoErrflow) CheckReadCloser(value io.ReadCloser, err error) io.ReadCloser
CheckReadCloser calls errf.Check and returns a typed value from a function call.
func (IoErrflow) CheckReadCloserErr ¶
func (ef IoErrflow) CheckReadCloserErr(value io.ReadCloser, err error) (io.ReadCloser, error)
CheckReadCloserErr calls errf.Check and returns a typed value and error from a function call.
func (IoErrflow) CheckReader ¶
CheckReader calls errf.Check and returns a typed value from a function call.
func (IoErrflow) CheckReaderErr ¶
CheckReaderErr calls errf.Check and returns a typed value and error from a function call.
func (IoErrflow) CheckWriteCloser ¶
func (ef IoErrflow) CheckWriteCloser(value io.WriteCloser, err error) io.WriteCloser
CheckWriteCloser calls errf.Check and returns a typed value from a function call.
func (IoErrflow) CheckWriteCloserErr ¶
func (ef IoErrflow) CheckWriteCloserErr(value io.WriteCloser, err error) (io.WriteCloser, error)
CheckWriteCloserErr calls errf.Check and returns a typed value and error from a function call.
func (IoErrflow) CheckWriter ¶
CheckWriter calls errf.Check and returns a typed value from a function call.
func (IoErrflow) CheckWriterErr ¶
CheckWriterErr calls errf.Check and returns a typed value and error from a function call.
func (IoErrflow) With ¶
func (ef IoErrflow) With(options ...ErrflowOption) IoErrflow
With implements Errflow.With(...) for io types.
type LogMessage ¶
type LogMessage struct { // Format is a format string. Format string // A contains arguments for Format string. A []interface{} // Stack function returns stacktrace string. Stack func() string // Tags contains additional tags. Tags []string }
LogMessage defines a single log message interface.
type OsErrflow ¶ added in v0.2.0
type OsErrflow struct {
// contains filtered or unexported fields
}
OsErrflow implements Check* functions for os package types.
Clients should not instantiate OsErrflow, use 'errf.Os' instead.
func (OsErrflow) CheckFile ¶ added in v0.2.0
CheckFile calls errflow.Check and returns a typed value from a function call.
func (OsErrflow) CheckFileErr ¶ added in v0.2.0
CheckFileErr calls errflow.Check and returns a typed value and error from a function call.
func (OsErrflow) With ¶ added in v0.2.0
func (ef OsErrflow) With(options ...ErrflowOption) OsErrflow
With implements Errflow.With(...) for os types.
type PanicErr ¶ added in v0.2.0
type PanicErr struct {
PanicObj interface{}
}
PanicErr is an error type, which is used in error fn Handle()... callbacks, in case if handler was triggered by a panic instead of an error.
See also: errf.IsPanic, errf.GetPanic.
type StdErrflow ¶
type StdErrflow struct {
// contains filtered or unexported fields
}
StdErrflow implements Check* functions for built-in types.
Clients should not instantiate StdErrflow, use 'errf.Std' instead.
func (StdErrflow) CheckBool ¶
func (ef StdErrflow) CheckBool(value bool, err error) bool
CheckBool calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckBoolErr ¶
func (ef StdErrflow) CheckBoolErr(value bool, err error) (bool, error)
CheckBoolErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckBoolSlice ¶
func (ef StdErrflow) CheckBoolSlice(value []bool, err error) []bool
CheckBoolSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckBoolSliceErr ¶
func (ef StdErrflow) CheckBoolSliceErr(value []bool, err error) ([]bool, error)
CheckBoolSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckByte ¶
func (ef StdErrflow) CheckByte(value byte, err error) byte
CheckByte calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckByteErr ¶
func (ef StdErrflow) CheckByteErr(value byte, err error) (byte, error)
CheckByteErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckByteSlice ¶
func (ef StdErrflow) CheckByteSlice(value []byte, err error) []byte
CheckByteSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckByteSliceErr ¶
func (ef StdErrflow) CheckByteSliceErr(value []byte, err error) ([]byte, error)
CheckByteSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckComplex128 ¶
func (ef StdErrflow) CheckComplex128(value complex128, err error) complex128
CheckComplex128 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckComplex128Err ¶
func (ef StdErrflow) CheckComplex128Err(value complex128, err error) (complex128, error)
CheckComplex128Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckComplex128Slice ¶
func (ef StdErrflow) CheckComplex128Slice(value []complex128, err error) []complex128
CheckComplex128Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckComplex128SliceErr ¶
func (ef StdErrflow) CheckComplex128SliceErr(value []complex128, err error) ([]complex128, error)
CheckComplex128SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckComplex64 ¶
func (ef StdErrflow) CheckComplex64(value complex64, err error) complex64
CheckComplex64 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckComplex64Err ¶
func (ef StdErrflow) CheckComplex64Err(value complex64, err error) (complex64, error)
CheckComplex64Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckComplex64Slice ¶
func (ef StdErrflow) CheckComplex64Slice(value []complex64, err error) []complex64
CheckComplex64Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckComplex64SliceErr ¶
func (ef StdErrflow) CheckComplex64SliceErr(value []complex64, err error) ([]complex64, error)
CheckComplex64SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckFloat32 ¶
func (ef StdErrflow) CheckFloat32(value float32, err error) float32
CheckFloat32 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckFloat32Err ¶
func (ef StdErrflow) CheckFloat32Err(value float32, err error) (float32, error)
CheckFloat32Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckFloat32Slice ¶
func (ef StdErrflow) CheckFloat32Slice(value []float32, err error) []float32
CheckFloat32Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckFloat32SliceErr ¶
func (ef StdErrflow) CheckFloat32SliceErr(value []float32, err error) ([]float32, error)
CheckFloat32SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckFloat64 ¶
func (ef StdErrflow) CheckFloat64(value float64, err error) float64
CheckFloat64 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckFloat64Err ¶
func (ef StdErrflow) CheckFloat64Err(value float64, err error) (float64, error)
CheckFloat64Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckFloat64Slice ¶
func (ef StdErrflow) CheckFloat64Slice(value []float64, err error) []float64
CheckFloat64Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckFloat64SliceErr ¶
func (ef StdErrflow) CheckFloat64SliceErr(value []float64, err error) ([]float64, error)
CheckFloat64SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt ¶
func (ef StdErrflow) CheckInt(value int, err error) int
CheckInt calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt16 ¶
func (ef StdErrflow) CheckInt16(value int16, err error) int16
CheckInt16 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt16Err ¶
func (ef StdErrflow) CheckInt16Err(value int16, err error) (int16, error)
CheckInt16Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt16Slice ¶
func (ef StdErrflow) CheckInt16Slice(value []int16, err error) []int16
CheckInt16Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt16SliceErr ¶
func (ef StdErrflow) CheckInt16SliceErr(value []int16, err error) ([]int16, error)
CheckInt16SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt32 ¶
func (ef StdErrflow) CheckInt32(value int32, err error) int32
CheckInt32 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt32Err ¶
func (ef StdErrflow) CheckInt32Err(value int32, err error) (int32, error)
CheckInt32Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt32Slice ¶
func (ef StdErrflow) CheckInt32Slice(value []int32, err error) []int32
CheckInt32Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt32SliceErr ¶
func (ef StdErrflow) CheckInt32SliceErr(value []int32, err error) ([]int32, error)
CheckInt32SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt64 ¶
func (ef StdErrflow) CheckInt64(value int64, err error) int64
CheckInt64 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt64Err ¶
func (ef StdErrflow) CheckInt64Err(value int64, err error) (int64, error)
CheckInt64Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt64Slice ¶
func (ef StdErrflow) CheckInt64Slice(value []int64, err error) []int64
CheckInt64Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt64SliceErr ¶
func (ef StdErrflow) CheckInt64SliceErr(value []int64, err error) ([]int64, error)
CheckInt64SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt8 ¶
func (ef StdErrflow) CheckInt8(value int8, err error) int8
CheckInt8 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt8Err ¶
func (ef StdErrflow) CheckInt8Err(value int8, err error) (int8, error)
CheckInt8Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckInt8Slice ¶
func (ef StdErrflow) CheckInt8Slice(value []int8, err error) []int8
CheckInt8Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckInt8SliceErr ¶
func (ef StdErrflow) CheckInt8SliceErr(value []int8, err error) ([]int8, error)
CheckInt8SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckIntErr ¶
func (ef StdErrflow) CheckIntErr(value int, err error) (int, error)
CheckIntErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckIntSlice ¶
func (ef StdErrflow) CheckIntSlice(value []int, err error) []int
CheckIntSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckIntSliceErr ¶
func (ef StdErrflow) CheckIntSliceErr(value []int, err error) ([]int, error)
CheckIntSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckRune ¶
func (ef StdErrflow) CheckRune(value rune, err error) rune
CheckRune calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckRuneErr ¶
func (ef StdErrflow) CheckRuneErr(value rune, err error) (rune, error)
CheckRuneErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckRuneSlice ¶
func (ef StdErrflow) CheckRuneSlice(value []rune, err error) []rune
CheckRuneSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckRuneSliceErr ¶
func (ef StdErrflow) CheckRuneSliceErr(value []rune, err error) ([]rune, error)
CheckRuneSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckString ¶
func (ef StdErrflow) CheckString(value string, err error) string
CheckString calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckStringErr ¶
func (ef StdErrflow) CheckStringErr(value string, err error) (string, error)
CheckStringErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckStringSlice ¶
func (ef StdErrflow) CheckStringSlice(value []string, err error) []string
CheckStringSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckStringSliceErr ¶
func (ef StdErrflow) CheckStringSliceErr(value []string, err error) ([]string, error)
CheckStringSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint ¶
func (ef StdErrflow) CheckUint(value uint, err error) uint
CheckUint calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint16 ¶
func (ef StdErrflow) CheckUint16(value uint16, err error) uint16
CheckUint16 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint16Err ¶
func (ef StdErrflow) CheckUint16Err(value uint16, err error) (uint16, error)
CheckUint16Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint16Slice ¶
func (ef StdErrflow) CheckUint16Slice(value []uint16, err error) []uint16
CheckUint16Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint16SliceErr ¶
func (ef StdErrflow) CheckUint16SliceErr(value []uint16, err error) ([]uint16, error)
CheckUint16SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint32 ¶
func (ef StdErrflow) CheckUint32(value uint32, err error) uint32
CheckUint32 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint32Err ¶
func (ef StdErrflow) CheckUint32Err(value uint32, err error) (uint32, error)
CheckUint32Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint32Slice ¶
func (ef StdErrflow) CheckUint32Slice(value []uint32, err error) []uint32
CheckUint32Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint32SliceErr ¶
func (ef StdErrflow) CheckUint32SliceErr(value []uint32, err error) ([]uint32, error)
CheckUint32SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint64 ¶
func (ef StdErrflow) CheckUint64(value uint64, err error) uint64
CheckUint64 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint64Err ¶
func (ef StdErrflow) CheckUint64Err(value uint64, err error) (uint64, error)
CheckUint64Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint64Slice ¶
func (ef StdErrflow) CheckUint64Slice(value []uint64, err error) []uint64
CheckUint64Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint64SliceErr ¶
func (ef StdErrflow) CheckUint64SliceErr(value []uint64, err error) ([]uint64, error)
CheckUint64SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint8 ¶
func (ef StdErrflow) CheckUint8(value uint8, err error) uint8
CheckUint8 calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint8Err ¶
func (ef StdErrflow) CheckUint8Err(value uint8, err error) (uint8, error)
CheckUint8Err calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUint8Slice ¶
func (ef StdErrflow) CheckUint8Slice(value []uint8, err error) []uint8
CheckUint8Slice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUint8SliceErr ¶
func (ef StdErrflow) CheckUint8SliceErr(value []uint8, err error) ([]uint8, error)
CheckUint8SliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUintErr ¶
func (ef StdErrflow) CheckUintErr(value uint, err error) (uint, error)
CheckUintErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUintSlice ¶
func (ef StdErrflow) CheckUintSlice(value []uint, err error) []uint
CheckUintSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUintSliceErr ¶
func (ef StdErrflow) CheckUintSliceErr(value []uint, err error) ([]uint, error)
CheckUintSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUintptr ¶
func (ef StdErrflow) CheckUintptr(value uintptr, err error) uintptr
CheckUintptr calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUintptrErr ¶
func (ef StdErrflow) CheckUintptrErr(value uintptr, err error) (uintptr, error)
CheckUintptrErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) CheckUintptrSlice ¶
func (ef StdErrflow) CheckUintptrSlice(value []uintptr, err error) []uintptr
CheckUintptrSlice calls errf.Check and returns a typed value from a function call.
func (StdErrflow) CheckUintptrSliceErr ¶
func (ef StdErrflow) CheckUintptrSliceErr(value []uintptr, err error) ([]uintptr, error)
CheckUintptrSliceErr calls errf.Check and returns a typed value and error from a function call.
func (StdErrflow) With ¶
func (ef StdErrflow) With(options ...ErrflowOption) StdErrflow
With implements Errflow.With(...) for built-in types.