Documentation ¶
Overview ¶
Package errors defines the error handling used by kpt codebase.
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func E(args ...interface{}) error
- func Is(err, target error) bool
- func UnwrapErrors(err error) (error, bool)
- func UnwrapKioError(err error) error
- type Class
- type Error
- type Fn
- type Op
- type Repo
- type ValidationError
- type Violation
- type ViolationType
- type Violations
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyHandled error = fmt.Errorf("already handled error")
ErrAlreadyHandled is an error that is already handled by a kpt command and nothing needs to be done by the global error handler except to return a non-zero exit code.
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
func UnwrapErrors ¶
UnwrapErrors unwraps any *Error errors in the chain and returns the first error it finds that is of a different type. If no such error can be found, the last return value will be false. nolint
func UnwrapKioError ¶
UnwrapKioError unwraps the error returned by kio pipeline. The error returned by kio pipeline is wrapped by library 'github.com/go-errors/errors' and it doesn't support 'Unwrap' method so 'errors.As' will not work. This function will return the first error wrapped by kio pipeline. If the error is not wrapped by kio pipeline, it will return the original error.
Types ¶
type Class ¶
type Class int
Class describes the class of errors encountered.
const ( Other Class = iota // Unclassified. Will not be printed. Exist // Item already exists. Internal // Internal error. InvalidParam // Value is not valid. MissingParam // Required value is missing or empty. Git // Errors from Git IO // Error doing IO operations YAML // yaml document can't be parsed )
type Error ¶
type Error struct { // Path is the path of the object (pkg, file) involved in kpt operation. Path types.UniquePath // Op is the operation being performed, for ex. pkg.get, fn.render Op Op // Fn is the kpt function being run either as part of "fn render" or "fn eval" Fn Fn // Repo is the git repo used for get, update or diff Repo Repo // Class refers to class of errors Class Class // Err refers to wrapped error (if any) Err error }
Error is the type that implements error interface used in the kpt codebase. It is based on the design in https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html The intent is to capture error information in a structured format so that we can display it differently to different users for ex. kpt developers are interested in operational trace along with more diagnostic information while kpt end-users may be just interested in a concise and actionable information. Representing errors in structured format helps us decouple the error information from how it is surfaced to the end users.
type ValidationError ¶
type ValidationError struct {
Violations Violations
}
ValidationError is an error type used when validation fails.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type Violation ¶
type Violation struct { Field string Value string Type ViolationType Reason string }
type ViolationType ¶
type ViolationType string
const ( Missing ViolationType = "missing" Invalid ViolationType = "invalid" )
type Violations ¶
type Violations []Violation
func (Violations) Fields ¶
func (v Violations) Fields() []string