Documentation
¶
Index ¶
- func Append(current error, next ...error) error
- func Embed[Data any](err error, key string, value Data) error
- func Expand(err error) []error
- func GetAllEmbeddedData(err error) map[string]interface{}
- func GetEmbeddedData[Data any](err error, key string) (Data, bool)
- func GetEmbeddedDataUnsafe(err error, key string) interface{}
- func Is(err error, code ErrorCode) bool
- func New(err error, code ErrorCode, text string) error
- func Newf(err error, code ErrorCode, format string, args ...any) error
- func Unwrap(err error) error
- func Wrap(err error, text string) error
- func Wrapf(err error, format string, args ...any) error
- type Codeable
- type DataContainer
- type DataContainingError
- type ErrorCode
- type Unwrappable
- type WrappingError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Expand ¶ added in v0.2.0
Expand will expand the provider error into multiple errors if it is a multi error. Otherwise, it will return a slice containing the single error.
func GetAllEmbeddedData ¶ added in v0.2.0
GetAllEmbeddedData returns all embedded data from an error if it exists. This function will automatically unwrap errors that are wrapped in other errors to find all metadata associated with the error.
func GetEmbeddedData ¶
GetEmbeddedData returns the embedded data from an error if it exists. This function will automatically unwrap errors that are wrapped in other errors to find all metadata associated with the error.
func GetEmbeddedDataUnsafe ¶ added in v0.2.0
GetEmbeddedDataUnsafe returns the embedded data from an error if it exists. This function will automatically unwrap errors that are wrapped in other errors to find all metadata associated with the error.
func New ¶
New returns an error with a new error code, optionally wrapping an existing error.
For example: errors.New(nil, ErrorCodeNotFound, "resource not found") For example: errors.New(err, ErrorCodeNotFound, "resource not found")
func Newf ¶
Newf returns an error with a new error code, optionally wrapping an existing error.
This matches New, but with a formatted message.
Types ¶
type DataContainer ¶
DataContainer is an interface for errors that contain embedded data.
type DataContainingError ¶
type DataContainingError struct { *WrappingError // contains filtered or unexported fields }
DataContainingError is an extension to the WrappingError struct that contains embedded data.
func (*DataContainingError) EmbeddedData ¶ added in v0.2.0
func (d *DataContainingError) EmbeddedData() map[string]interface{}
EmbeddedData implements the DataContainer interface.
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a code that can be used to identify the type of error.
const ( // ErrorCodeUnknown is the default error code returned when an error hasn't been assigned a code. ErrorCodeUnknown ErrorCode = "ErrorCodeUnknown" // ErrorCodeOk is the error code returned when an error is nil. ErrorCodeOk ErrorCode = "ErrorCodeOk" // ErrorCodeWrapped is the error code returned when an error is wrapped by another error. ErrorCodeWrapped ErrorCode = "ErrorCodeWrapped" // ErrorCodeMulti is the error code returned when an error contains multiple errors. ErrorCodeMulti ErrorCode = "ErrorCodeMulti" )
func GetErrorCode ¶
GetErrorCode returns the error code of the given error.
type Unwrappable ¶
Unwrappable is an interface for errors that can be unwrapped.
type WrappingError ¶
type WrappingError struct {
// contains filtered or unexported fields
}
WrappingError is an error that can wrap another error.
func (*WrappingError) Error ¶
func (e *WrappingError) Error() string
Error implements the error interface.
func (*WrappingError) GetErrorCode ¶
func (e *WrappingError) GetErrorCode() ErrorCode
GetErrorCode implements the Codeable interface.
func (*WrappingError) Unwrap ¶
func (e *WrappingError) Unwrap() error
Unwrap implements the Unwrappable interface.