errors

package
v1.104.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errors added in v0.34.0

func Errors(err error) []error

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

func GetID(err error) string

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

func Suppressed(err error) error

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

func Unwrap(err error) error

Unwrap unwraps and returns the root error. Multiple wrappings via `fmt.Errorf` implementations are properly taken into account.

func WithID

func WithID(id string, err error) error

WithID annotates the error with the given errorID which can afterwards be retrieved by ErrorID()

func WithSuppressed

func WithSuppressed(err, suppressed error) error

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

type FailureHandler func(string, error) error

FailureHandler is a function which is called when an error occurs

type SuccessHandler

type SuccessHandler func(string) error

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

func ToExecute

func ToExecute(errorID string, task func() error) TaskFunc

ToExecute takes an errorID and a function and creates a TaskFunc from them.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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