Documentation ¶
Overview ¶
Package errorx provides extended error handling functionality.
Index ¶
- type BaseError
- func (b *BaseError) Append(errs ...Error)
- func (b *BaseError) Attr(key string) (any, error)
- func (b *BaseError) AttrDuration(key string) (time.Duration, error)
- func (b *BaseError) AttrInt(key string) (int, error)
- func (b *BaseError) AttrInt64(key string) (int64, error)
- func (b *BaseError) AttrString(key string) (string, error)
- func (b *BaseError) AttrTime(key string) (time.Time, error)
- func (b *BaseError) AttrUint(key string) (uint, error)
- func (b *BaseError) AttrUint64(key string) (uint64, error)
- func (b *BaseError) Attrs() map[string]any
- func (b *BaseError) Code() int
- func (b *BaseError) Error() string
- func (b *BaseError) InternalError() error
- func (b *BaseError) NestedErrors() []Error
- func (b *BaseError) WithAttr(attrKey string, attrValue any) *BaseError
- func (b *BaseError) WithAttrs(attrs map[string]any) *BaseError
- type Error
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 is a base error object that mostly implements the Error interface and can be used to more easily compose more type-specific errors. Composed objects must implement the Error() function.
Do not create this object directly. Use NewBaseError() to construct a new object so its values are initialized properly.
func NewBaseError ¶
NewBaseError returns a new BaseError object without caller information enabled.
func (*BaseError) Append ¶
Append appends one or more non-nil errors to the end of the list of nested errors associated with this error.
Any nil errors passed are ignored.
func (*BaseError) AttrDuration ¶
AttrDuration returns the value of the attribute with the given key (if it exists) as a time duration.
func (*BaseError) AttrInt ¶
AttrInt returns the value of the attribute with the given key (if it exists) as an integer if it exists.
func (*BaseError) AttrInt64 ¶
AttrInt64 returns the value of the attribute with the given key (if it exists) as a 64-bit integer.
func (*BaseError) AttrString ¶
AttrString returns the value of the attribute with the given key (if it exists) as a string.
func (*BaseError) AttrTime ¶
AttrTime returns the value of the attribute with the given key (if it exists) as a time object.
func (*BaseError) AttrUint ¶
AttrUint returns the value of the attribute with the given key (if it exists) as an unsigned integer.
func (*BaseError) AttrUint64 ¶
AttrUint64 returns the value of the attribute with the given key (if it exists) as an unsigned 64-bit integer.
func (*BaseError) Attrs ¶
Attrs returns all of the attributes associated with the error.
If this object has no attributes defined, an empty map is returned.
func (*BaseError) InternalError ¶
InternalError returns the standard error associated with the object.
The error returned by this function is guaranteed to never be `nil`.
func (*BaseError) NestedErrors ¶
NestedErrors returns the list of errors that were generated by a call to another function.
If there are no nested errors, an empty list is returned.
type Error ¶
type Error interface { // Attrs should return any additional attributes which may be used when logging the error. Attrs() map[string]any // Code should return the corresponding error code. Code() int // Error should return the string version of the error. Error() string // InternalError should return the internal standard error object if there is one. InternalError() error // NestedErrors should return the list of nested errors if there are any. NestedErrors() []Error }
Error represents an extension to the standard error interface by adding the ability to include an error code, nested errors, and any attributes associated with the error.