gardener: github.com/gardener/gardener/pkg/utils/errors Index | Files

package errors

import "github.com/gardener/gardener/pkg/utils/errors"

Index

Package Files

errors.go multierror.go

func Cancel Uses

func Cancel() error

Cancel returns an error which will cause the HandleErrors function to stop executing tasks without triggering its FailureHandler.

func Errors Uses

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 Uses

func GetID(err error) string

GetID returns the ID of the error if possible. If err does not implement ErrorID or is nill an empty string will be returned.

func HandleErrors Uses

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 Uses

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 Uses

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 WasCanceled Uses

func WasCanceled(err error) bool

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 Uses

func WithID(id string, err error) error

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

func WithSuppressed Uses

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.

type ErrorContext Uses

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 Uses

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 Uses

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 Uses

func (e *ErrorContext) HasErrorWithID(errorID string) bool

HasErrorWithID checks if the ErrorContext already contains an error with id errorID

func (*ErrorContext) HasLastErrorWithID Uses

func (e *ErrorContext) HasLastErrorWithID(errorID string) bool

HasLastErrorWithID checks if the previous reconciliation had encountered an error with id errorID

type FailureHandler Uses

type FailureHandler func(string, error) error

FailureHandler is a function which is called when an error occurs

type SuccessHandler Uses

type SuccessHandler func(string) error

SuccessHandler is called when a task completes successfully

type TaskFunc Uses

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 Uses

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

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

Package errors imports 3 packages (graph) and is imported by 7 packages. Updated 2020-02-20. Refresh now. Tools for package owners.