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 ¶ added in v1.0.10
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 ¶ added in v1.1.0
NewBaseError returns a new BaseError object without caller information enabled.
func (*BaseError) Append ¶ added in v1.1.0
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) Attr ¶ added in v1.0.10
Attr returns the value of the attribute with the given key if it exists.
func (*BaseError) AttrDuration ¶ added in v1.0.10
AttrDuration returns the value of the attribute with the given key (if it exists) as a time duration.
func (*BaseError) AttrInt ¶ added in v1.0.10
AttrInt returns the value of the attribute with the given key (if it exists) as an integer if it exists.
func (*BaseError) AttrInt64 ¶ added in v1.0.10
AttrInt64 returns the value of the attribute with the given key (if it exists) as a 64-bit integer.
func (*BaseError) AttrString ¶ added in v1.0.10
AttrString returns the value of the attribute with the given key (if it exists) as a string.
func (*BaseError) AttrTime ¶ added in v1.0.10
AttrTime returns the value of the attribute with the given key (if it exists) as a time object.
func (*BaseError) AttrUint ¶ added in v1.0.10
AttrUint returns the value of the attribute with the given key (if it exists) as an unsigned integer.
func (*BaseError) AttrUint64 ¶ added in v1.0.10
AttrUint64 returns the value of the attribute with the given key (if it exists) as an unsigned 64-bit integer.
func (*BaseError) Attrs ¶ added in v1.0.10
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 ¶ added in v1.0.10
InternalError returns the standard error associated with the object.
The error returned by this function is guaranteed to never be `nil`.
func (*BaseError) NestedErrors ¶ added in v1.0.10
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 ¶ added in v1.0.10
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.