errors

package
v1.0.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package errors defines the error handling used by kpt codebase.

Index

Constants

This section is empty.

Variables

View Source
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

func As(err error, target interface{}) bool

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 E

func E(args ...interface{}) error

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

func UnwrapErrors

func UnwrapErrors(err error) (error, bool)

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

func UnwrapKioError(err error) error

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
)

func (Class) String

func (c Class) String() string

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.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) Zero

func (e *Error) Zero() bool

type Fn

type Fn string

Fn describes the kpt function associated with the error.

type Op

type Op string

Op describes the operation being performed.

type Repo

type Repo string

Repo describes the repo associated with the error.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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