errors

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: BSD-3-Clause Imports: 6 Imported by: 36

Documentation

Index

Constants

View Source
const (
	// ErrorCodeEmpty is an empty error code
	// Deprecated: prefer CodeEmpty
	ErrorCodeEmpty = CodeEmpty

	// CodeEmpty is the zero-value for error codes
	CodeEmpty = Code("")
)
View Source
const (
	// SeverityUnset indicates the severity was not set
	SeverityUnset = Severity("")
	// SeverityRuntime indicates the error is returned for an operation that should/could be executed again. For example, timeouts.
	SeverityRuntime = Severity("runtime")
	// SeverityFatal indicates the error is unrecoverable and the execution should stop, or not being retried.
	SeverityFatal = Severity("fatal")
	// SeverityInput indicates  an expected, like a bad user input/request. For example, an invalid email.
	SeverityInput = Severity("input")
)

Variables

This section is empty.

Functions

func ConcatErrors

func ConcatErrors(errs ...error) error

ConcatErrors concatenates all errors

func ConcatErrorsMessage

func ConcatErrorsMessage(errs ...error) string

ConcatErrorsMessage concatenates all the error messages from the given errors

func DontPanic

func DontPanic(f func()) (err error)

DontPanic executes f and, if f panics, recovers from the panic and returns the panic wrapped as an Error.

func E

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

E is a helper function for builder errors

func EqualsCode

func EqualsCode(lCode, rCode Code) bool

EqualsCode returns true if @lCode and @rCode holds the same value, and false otherwise

func Errorf

func Errorf(s string, params ...interface{}) error

Errorf returns a error based on given params

func GetRootError

func GetRootError(err error) error

GetRootError returns the Err field of Error struct or the error itself if it is of another type

func GetRootErrorWithKV

func GetRootErrorWithKV(err error) error

GetRootErrorWithKV returns the Err field of Error struct or the error itself if it is of another type

func New

func New(s string) error

New returns a new error

func SameCode

func SameCode(lError, rError error) bool

SameCode returns true if @lError and @rError holds error codes with the same value, and false otherwise. If one or both errors have no code, SameCode will return false.

Types

type Code

type Code string

Code is the error code

var CodePanic Code = "PANIC"

CodePanic represents the error code for panic

func GetCode

func GetCode(err error) Code

GetCode returns the error code. If the error doesn't contains an error code, returns ErrorCodeEmpty

func GetErrorCode deprecated

func GetErrorCode(err error) Code

GetErrorCode returns the error code. If the error doesn't contains an error code, returns ErrorCodeEmpty.

Deprecated: use GetCode instead.

func (Code) MarshalZerologObject

func (c Code) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject allows for zerolog to log the error code as 'error_code': '...'

func (Code) String

func (c Code) String() string

String returns the code as a string

type Error

type Error struct {
	Severity Severity
	Err      error
	Code     Code
	Op       Op
	KVs      []KeyValue
}

Error represents the error struct that should be returned in all functions Error implements the Go's error interface

func NewFromRecover

func NewFromRecover(r interface{}) Error

NewFromRecover returns a new Error created from the result of a recover. If r is an Error, this will be used so Op and KV are preserved

func (Error) Error

func (e Error) Error() string

func (Error) String

func (e Error) String() string

type KeyValue

type KeyValue struct {
	Key   interface{}
	Value interface{}
}

KeyValue is used to store a key-value pair within the error

func KV

func KV(k, v interface{}) KeyValue

KV is a constructor for KeyValue types

func (KeyValue) String

func (kv KeyValue) String() string

type Op

type Op string

Op is the operation that encapsulated the error

func (Op) String

func (o Op) String() string

type Severity

type Severity string

Severity is the error severity. It's used to classify errors in groups to be easily handled by the code. For example, a retry layer should be only checking for Runtime errors to retry. Or in an HTTP layer, errors of input type are always returned a 400 status.

func GetSeverity

func GetSeverity(err error) Severity

GetSeverity returns the error severity. If there is not severity, SeverityUnset is returned.

func (Severity) MarshalZerologObject

func (s Severity) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject allows for zerolog to log the error severity as 'error_severity': '...'

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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