{"modulePath":"github.com/kptdev/kpt","version":"v1.0.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors defines the error handling used by kpt codebase.\n\n## Variables\n\n```go\nvar ErrAlreadyHandled = fmt.Errorf(\"already handled error\")\n```\nErrAlreadyHandled 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.\n\n## Functions\n\n```go\nfunc As(err error, target any) bool\n```\nAs 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.\n\n```go\nfunc E(args ...any) error\n```\n\n```go\nfunc Is(err, target error) bool\n```\nIs reports whether any error in err's chain matches target.\n\n```go\nfunc UnwrapErrors(err error) (error, bool)\n```\nUnwrapErrors 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\n\n```go\nfunc UnwrapKioError(err error) error\n```\nUnwrapKioError 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.\n\n## Types\n\n```go\ntype Class int\n```\nClass describes the class of errors encountered.\n\n```go\nconst (\n\tOther        Class = iota // Unclassified. Will not be printed.\n\tExist                     // Item already exists.\n\tInternal                  // Internal error.\n\tInvalidParam              // Value is not valid.\n\tMissingParam              // Required value is missing or empty.\n\tGit                       // Errors from Git\n\tIO                        // Error doing IO operations\n\tYAML                      // yaml document can't be parsed\n)\n```\n\n```go\nfunc (c Class) String() string\n```\n\n```go\ntype Error struct {\n\t// Path is the path of the object (pkg, file) involved in kpt operation.\n\tPath kptfilev1.UniquePath\n\n\t// Op is the operation being performed, for ex. pkg.get, fn.render\n\tOp Op\n\n\t// Fn is the kpt function being run either as part of \"fn render\" or \"fn eval\"\n\tFn Fn\n\n\t// Repo is the git repo used for get, update or diff\n\tRepo Repo\n\n\t// Class refers to class of errors\n\tClass Class\n\n\t// Err refers to wrapped error (if any)\n\tErr error\n}\n```\nError 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](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.\n\n```go\nfunc (e *Error) Error() string\n```\n\n```go\nfunc (e *Error) Unwrap() error\n```\n\n```go\nfunc (e *Error) Zero() bool\n```\n\n```go\ntype Fn string\n```\nFn describes the kpt function associated with the error.\n\n```go\ntype Op string\n```\nOp describes the operation being performed.\n\n```go\ntype Repo string\n```\nRepo describes the repo associated with the error.\n\n```go\ntype ValidationError struct {\n\tViolations Violations\n}\n```\nValidationError is an error type used when validation fails.\n\n```go\nfunc (e *ValidationError) Error() string\n```\n\n```go\ntype Violation struct {\n\tField  string\n\tValue  string\n\tType   ViolationType\n\tReason string\n}\n```\n\n```go\ntype ViolationType string\n```\n\n```go\nconst (\n\tMissing ViolationType = \"missing\"\n\tInvalid ViolationType = \"invalid\"\n)\n```\n\n```go\ntype Violations []Violation\n```\n\n```go\nfunc (v Violations) Fields() []string\n```\n\n","path":"github.com/kptdev/kpt/pkg/lib/errors","name":"errors","synopsis":"Package errors defines the error handling used by kpt codebase.","isRedistributable":true}
