errors

package
v0.35.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Internal

func Internal(err error) error

Internal generates an instance representing an error that occurs when an internal error is thrown during the command execution.

func Invalid

func Invalid(name string, value interface{}) error

Invalid generates an instance representing an error that occurs when a string parameter is set a malformed value (e.g. failed regex match, too long).

func NewError added in v0.0.10

func NewError(typ ErrorType, detail string) error

NewError generates a custom error.

func Noninteractive added in v0.0.6

func Noninteractive(op string) error

Noninteractive generates an instance representing an error that occurs when a command cannot run in non-interactive mode.

func NotImplemented

func NotImplemented() error

NotImplemented generates an instance representing an error that occurs when an unimplemented method is called.

func Range

func Range(name string, value interface{}) error

Range generates an instance representing an error that occurs when a numeric parameter is outside of its valid range.

func Required

func Required(name string) error

Required generates an instance representing an error that occurs when a required parameter is missing.

func RequiredAnd added in v0.0.16

func RequiredAnd(names ...string) error

RequiredAnd generates an instance representing an error that occurs when all parameters must appear together. And defines an all-or-nothing relationship between parameters where if one of the peers is present, all of them are required as well.

func RequiredOr added in v0.0.16

func RequiredOr(names ...string) error

RequiredOr generates an instance representing an error that occurs when at least one parameter must appear. Or defines a relationship between parameters where one of the peers is required (and more than one is allowed).

func RequiredXor added in v0.0.16

func RequiredXor(names ...string) error

RequiredXor generates an instance representing an error that occurs when exclusive parameters must not appear together but where one of them is required. Or defines an exclusive relationship between a set of parameters where one of them is required but not at the same time.

Types

type Error

type Error struct {
	// Type defines an error type, expressed as a string value.
	Type ErrorType `json:"type"`

	// Detail defines a human-readable explanation specific to the error.
	Detail string `json:"detail"`
}

Error provides a way to return detailed information for an error.

func (*Error) Error

func (e *Error) Error() string

Error implements the `error` interface.

type ErrorGroup added in v0.0.10

type ErrorGroup struct {
	// contains filtered or unexported fields
}

ErrorGroup is an error type to track multiple errors. This is used to accumulate errors in cases and return them as a single error.

func NewErrorGroup added in v0.0.10

func NewErrorGroup() *ErrorGroup

NewErrorGroup returns a new error group.

func (*ErrorGroup) Add added in v0.0.10

func (e *ErrorGroup) Add(err error)

Add adds a new error to the group.

func (*ErrorGroup) Error added in v0.0.10

func (e *ErrorGroup) Error() string

Error implements the internal error interface.

func (*ErrorGroup) Errors added in v0.0.10

func (e *ErrorGroup) Errors() []error

Errors returns the list of errors that this group is wrapping.

func (*ErrorGroup) Len added in v0.0.10

func (e *ErrorGroup) Len() int

Len implements sort.Interface function for length.

func (*ErrorGroup) Less added in v0.0.10

func (e *ErrorGroup) Less(i, j int) bool

Less implements sort.Interface function for determining order.

func (*ErrorGroup) Swap added in v0.0.10

func (e *ErrorGroup) Swap(i, j int)

Swap implements sort.Interface function for swapping elements.

type ErrorType

type ErrorType string

ErrorType represents the type of an error.

const (
	// ErrorTypeInternal is used to represent an error that occurs when an internal
	// error is thrown during the command execution.
	ErrorTypeInternal ErrorType = "InternalError"

	// ErrorTypeRequired is used to represent an error that occurs when a required
	// parameter is missing.
	ErrorTypeRequired ErrorType = "RequiredError"

	// ErrorTypeInvalid is used to represent an error that occurs when a string
	// parameter is set a malformed value (e.g. failed regex match, too long).
	ErrorTypeInvalid ErrorType = "InvalidError"

	// ErrorTypeRange is used to represent an error that occurs when a numeric
	// parameter is outside of its valid range.
	ErrorTypeRange ErrorType = "RangeError"

	// ErrorTypeNotImplemented is used to represent an error that occurs when
	// an unimplemented method is called.
	ErrorTypeNotImplemented ErrorType = "NotImplementedError"
)

Jump to

Keyboard shortcuts

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