Documentation ¶
Index ¶
- func Cancel() error
- func Errors(err error) []error
- func GetID(err error) string
- func HandleErrors(errorContext *ErrorContext, onSuccess SuccessHandler, onFailure FailureHandler, ...) error
- func NewErrorFormatFuncWithPrefix(prefix string) multierror.ErrorFormatFunc
- func Suppressed(err error) error
- func Unwrap(err error) error
- func WasCanceled(err error) bool
- func WithID(id string, err error) error
- func WithSuppressed(err, suppressed error) error
- type ErrorContext
- type FailureHandler
- type SuccessHandler
- type TaskFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cancel ¶
func Cancel() error
Cancel returns an error which will cause the HandleErrors function to stop executing tasks without triggering its FailureHandler.
func Errors ¶ added in v0.34.0
Errors returns a list of all nested errors of the given error. If the error is nil, nil is returned. If the error is a multierror, it returns all its errors. Otherwise, it returns a slice containing the error as single element.
func GetID ¶
GetID returns the ID of the error if possible. If err does not implement ErrorID or is nil an empty string will be returned.
func HandleErrors ¶
func HandleErrors(errorContext *ErrorContext, onSuccess SuccessHandler, onFailure FailureHandler, tasks ...TaskFunc) error
HandleErrors takes a reference to an ErrorContext, onSuccess and onFailure callback functions and a variadic list of taskFuncs. It sequentially adds the Tasks' errorIDs to the provided ErrorContext and executes them. If the ErrorContext has errors from the previous reconciliation and the tasks which caused errors complete successfully OnSuccess is called. If a task fails OnFailure is called
func NewErrorFormatFuncWithPrefix ¶ added in v1.1.0
func NewErrorFormatFuncWithPrefix(prefix string) multierror.ErrorFormatFunc
NewErrorFormatFuncWithPrefix creates a new multierror.ErrorFormatFunc which can be used as an ErrorFormat on multierror.Error instances. The error string is prefixed with <prefix>, all errors are concatenated at the end. This is similar to multierror.ListFormatFunc but does not use any escape sequences, which will look weird in the status of Kubernetes objects or controller logs.
func Suppressed ¶
Suppressed retrieves the suppressed error of the given error, if any. An error has a suppressed error if it implements the following interface:
type suppressor interface { Suppressed() error }
If the error does not implement the interface, nil is returned.
func Unwrap ¶ added in v1.28.0
Unwraps and returns the root error. Multiple wrappings either via `fmt.Errorf` or via `causer` implementations are properly taken into account.
func WasCanceled ¶
WasCanceled checks to see if the HandleErrors function was canceled manually. It can be used to check if execution after HandleErrors should be stopped without returning an error
func WithID ¶
WithID annotates the error with the given errorID which can afterwards be retrieved by ErrorID()
func WithSuppressed ¶
WithSuppressed annotates err with a suppressed error. If err is nil, WithSuppressed returns nil. If suppressed is nil, WithSuppressed returns err.
Types ¶
type ErrorContext ¶
type ErrorContext struct {
// contains filtered or unexported fields
}
The ErrorContext holds the lastError IDs from the previous reconciliaton and the IDs of the errors that are processed in this context during the current reconciliation
func NewErrorContext ¶
func NewErrorContext(name string, lastErrorIDs []string) *ErrorContext
NewErrorContext creates a new error context with the given name and lastErrors from the previous reconciliation
func (*ErrorContext) AddErrorID ¶
func (e *ErrorContext) AddErrorID(errorID string)
AddErrorID adds an error ID which will be tracked by the context and panics if more than one error have the same ID
func (*ErrorContext) HasErrorWithID ¶
func (e *ErrorContext) HasErrorWithID(errorID string) bool
HasErrorWithID checks if the ErrorContext already contains an error with id errorID
func (*ErrorContext) HasLastErrorWithID ¶
func (e *ErrorContext) HasLastErrorWithID(errorID string) bool
HasLastErrorWithID checks if the previous reconciliation had encountered an error with id errorID
type FailureHandler ¶
FailureHandler is a function which is called when an error occurs
type SuccessHandler ¶
SuccessHandler is called when a task completes successfully
type TaskFunc ¶
type TaskFunc interface {
Do(errorContext *ErrorContext) (string, error)
}
TaskFunc is an interface for a task which should belong to an ErrorContext and can trigger OnSuccess and OnFailure callbacks depending on whether it completes successfully or not