errors

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Is  = errors.Is
	As  = errors.As
	New = errors.New
)

These aliased values are added to avoid conflicting imports of standard `errors` package and this `errors` package where these functions are needed.

View Source
var (
	ErrInvalid     = Error{Code: "bad_request", Message: "Request is not valid"}
	ErrNotFound    = Error{Code: "not_found", Message: "Requested entity not found"}
	ErrConflict    = Error{Code: "conflict", Message: "An entity with conflicting identifier exists"}
	ErrInternal    = Error{Code: "internal_error", Message: "Some unexpected error occurred"}
	ErrUnsupported = Error{Code: "unsupported", Message: "Requested feature is not supported"}
)

Common error categories. Use `ErrX.WithXXX()` to clone and add context.

Functions

func Errorf

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

Errorf returns a formatted error similar to `fmt.Errorf` but uses the Error type defined in this package. returned value is equivalent to ErrInternal (i.e., errors.Is(retVal, ErrInternal) = true).

func OneOf

func OneOf(err error, others ...error) bool

OneOf checks if the error is one of the 'others'.

func Verbose

func Verbose(err error) error

Verbose returns a verbose error value.

Types

type Error

type Error struct {
	Code    string `json:"code"`
	Cause   string `json:"cause,omitempty"`
	Message string `json:"message"`
}

Error represents any error returned by the Entropy components along with any relevant context.

func E

func E(err error) Error

E converts any given error to the Error type. Unknown are converted to ErrInternal.

func (Error) Error

func (err Error) Error() string

func (Error) Is

func (err Error) Is(other error) bool

Is checks if 'other' is of type Error and has the same code. See https://blog.golang.org/go1.13-errors.

func (Error) WithCausef

func (err Error) WithCausef(format string, args ...interface{}) Error

WithCausef returns clone of err with the cause added. Use this when you need to provide description of the underlying technical root-cause which may be written in log for debugging purposes. Cause will be shown to the user only when the Message is empty.

func (Error) WithMsgf

func (err Error) WithMsgf(format string, args ...interface{}) Error

WithMsgf returns a clone of the error with message set. Use this when you need to provide a custom message that should be shown to the user. If the message is set to empty string, cause will be displayed to the user.

Jump to

Keyboard shortcuts

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