Documentation ¶
Overview ¶
Package cerrors contains functions related to error handling.
The standard library's errors package is missing some functionality which we need, such as stack traces. To be certain that all errors created in Conduit are created with the additional information, usage of this package is mandatory.
At present, the package acts as a "thin forwarding layer", where we "mix and match" functions from different packages.
Package cerrors contains functions related to error handling.
The standard library's errors package is missing some functionality which we need, such as stack traces. To be certain that all errors created in Conduit are created with the additional information, usage of this package is mandatory.
At present, the package acts as a "thin forwarding layer", where we "mix and match" functions from different packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // xerrors is used, since it provides the stack traces too New = xerrors.New //nolint:forbidigo // xerrors.New is allowed here, but not anywhere else Errorf = xerrors.Errorf //nolint:forbidigo // xerrors.Errorf is allowed here, but not anywhere else Is = errors.Is As = errors.As Unwrap = errors.Unwrap Join = errors.Join )
var ( // ErrNotImpl should be used when a functionality which is not yet implemented was called. ErrNotImpl = New("not impl") // ErrEmptyID should be used when an entity was requested, but the ID was not provided. ErrEmptyID = New("empty ID") )
Functions ¶
func GetStackTrace ¶
func GetStackTrace(err error) interface{}
func LogOrReplace ¶ added in v0.3.0
LogOrReplace is a utility meant to be called in deferred functions that can produce an error. In that case we have two options:
- Group errors together (e.g. with the multierror package).
- Use LogOrReplace to either log the error or return it.
The second option is preferable when the original error returning from the function is more important than the deferred error. LogOrReplace will return the original error if it is not nil, otherwise it will return the new error. If both errors are not nil, then the log function will be called, that can be used to log the new error.
Example how it's supposed to be used:
func() (err error) { defer func() { cleanupErr := cleanup() err = cerrors.LogOrReplace(err, cleanupErr, func() { fmt.Printf("cleanup error: %v", cleanupErr) }) } // execute logic that can produce an error return err }