errors

package
v0.0.0-...-84802a9 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: LGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 return true.

func Errorf

func Errorf(kind Kind, format string, args ...interface{}) error

Errorf formats according to a format specifier and return an unknown error with the string.

func IsKind

func IsKind(err error, kind Kind) bool

IsKind checks whether any error in err's chain matches the error kind.

func New

func New(kind Kind, msg string) error

New returns an error with the supplied kind and message. If message is empty, a default message, for the error kind will be used.

func ToUnderScore

func ToUnderScore(name string) string

ToUnderScore converts CamalCase to under_score case Source: https://gist.github.com/zxh/cee082053aa9674812e8cd4387088301

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

Same as Go's errors.Unwrap.

func WithFieldViolations

func WithFieldViolations(kind Kind, msg string, fieldViolations []FieldViolation) error

WithFieldViolations returns an error with supplied field violations.

func WithValidateError

func WithValidateError(err error) error

WithValidateError maps a Validate error into an internal error representation.

func Wrap

func Wrap(err error, kind Kind, msg string) error

Wrap returns an error annotating err with a kind and a stacktrace at the point Wrap is called, and the supplied kind and message. If err is nil, Wrap returns nil.

func Wrapf

func Wrapf(err error, kind Kind, format string, args ...interface{}) error

Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the kind and format specifier. If err is nil, Wrapf returns nil.

Types

type Error

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

Error is an internal errors with stacktrace. It can be converted to a HTTP response.

func (*Error) FieldViolations

func (e *Error) FieldViolations() []FieldViolation

FieldViolations returns a structure that represents field validation errors.

func (*Error) Kind

func (e *Error) Kind() Kind

Kind returns the error kind.

type FieldViolation

type FieldViolation struct {
	Field       string
	Description string
}

FieldViolation is a struct for providing field error details in HTTP error. It matches the same struct in errdetails package.

type Kind

type Kind string

Kind is the kind of error.

const (
	ErrorReadConfig       Kind = "config read error"
	ErrorParseConfig      Kind = "config parse error"
	ErrorNotImplemented   Kind = "not implement"
	ErrorCanceled         Kind = "canceled"
	ErrorUnknown          Kind = "unknown error"
	ErrorInvalidArgument  Kind = "invalid argument"
	ErrorDeadlineExceeded Kind = "deadline exceeded"
	ErrorNotFound         Kind = "entity not found"
	ErrorAlreadyExists    Kind = "already exists"
)

Error kinds.

Jump to

Keyboard shortcuts

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