errors

package
v1.0.41 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseError

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

BaseError generalizes an error structure which can be used for any type of error

func BaseErrorWrapper added in v1.0.14

func BaseErrorWrapper(err Error) BaseError

BaseErrorWrapper creates a new BaseError by wrapping an existing Error

func NewBaseError

func NewBaseError(kind ErrKind, errMsg string, err error, detail ErrDetails) BaseError

NewBaseError creates a new BaseError with the information provided

func ToBaseError

func ToBaseError(err error) BaseError

ToBaseError creates a new BaseError with Kind found from err

func (BaseError) AddDetail

func (be BaseError) AddDetail(key string, detail any)

AddDetail adds a detail associated with key for this BaseError.

func (BaseError) Code added in v1.0.38

func (be BaseError) Code() int

Code always returns 1 because BaseError is just a generic error that does not contain an error code. To get a specific error code, wrap BaseError using a more detailed error type, such as NewHTTPError.

func (BaseError) DebugMessages

func (be BaseError) DebugMessages() string

DebugMessages returns a string taking all nested and wrapped operations and errors into account.

func (BaseError) Error

func (be BaseError) Error() string

Error implements the Error interface for the BaseError struct

func (BaseError) Is

func (be BaseError) Is(err error) bool

Is determines if an error is of type BaseError. This is used by the new wrapping and unwrapping features available in Go 1.13 and aids the errors.Is function when determining is an error or any error in the wrapped chain contains an error of a particular type.

func (BaseError) Kind

func (be BaseError) Kind() string

Kind returns the error kind of this BaseError.

func (BaseError) Message

func (be BaseError) Message() string

Message returns the first level error message without further details.

func (BaseError) Unwrap

func (be BaseError) Unwrap() error

Unwrap retrieves the next nested error in the wrapped error chain. This is used by the new wrapping and unwrapping features available in Go 1.13 and aids in traversing the error chain of wrapped errors.

type ErrDetails

type ErrDetails map[string]any

ErrDetails is a detailed mapping to set extra information with the error

func Details added in v1.0.35

func Details(err error) ErrDetails

Details extracts error details from the given error. If the error is not of type BaseError, it returns nil.

type ErrKind

type ErrKind string

ErrKind a categorical identifier used to give high-level insight as to the error type.

const (
	// Constant Kind identifiers which can be used to label and group errors.
	KindUnknown               ErrKind = "Unknown"
	KindDatabaseError         ErrKind = "Database"
	KindCommunicationError    ErrKind = "Communication"
	KindEntityDoesNotExist    ErrKind = "NotFound"
	KindContractInvalid       ErrKind = "ContractInvalid"
	KindServerError           ErrKind = "UnexpectedServerError"
	KindLimitExceeded         ErrKind = "LimitExceeded"
	KindStatusConflict        ErrKind = "StatusConflict"
	KindDuplicateName         ErrKind = "DuplicateName"
	KindInvalidId             ErrKind = "InvalidId"
	KindServiceUnavailable    ErrKind = "ServiceUnavailable"
	KindNotAllowed