errorx

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 2 Imported by: 2

README

error logo

go-errorx

Extended error logging library for Golang






Table of Contents

👁️ Overview

go-errorx provides extended error logging for Go applications and packages. It extends the error interface by adding the ability to include an error code, nested errors, and any attributes associated with the error.

Please review the module documentation for details on how to properly the functions and classes contained in this module.

✅ Requirements

This module is supported for Go v1.18 and later.

📃 License

This module is distributed under the MIT License.

❓ Questions, Issues and Feature Requests

If you have questions about this project, find a bug or wish to submit a feature request, please submit an issue.

Documentation

Overview

Package errorx provides extended error handling functionality.

Index

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

func NewBaseError(code int, err error) *BaseError

NewBaseError returns a new BaseError object without caller information enabled.

func (*BaseError) Append added in v1.1.0

func (b *BaseError) Append(errs ...Error)

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

func (b *BaseError) Attr(key string) (any, error)

Attr returns the value of the attribute with the given key if it exists.

func (*BaseError) AttrDuration added in v1.0.10

func (b *BaseError) AttrDuration(key string) (time.Duration, error)

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

func (b *BaseError) AttrInt(key string) (int, error)

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

func (b *BaseError) AttrInt64(key string) (int64, error)

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

func (b *BaseError) AttrString(key string) (string, error)

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

func (b *BaseError) AttrTime(key string) (time.Time, error)

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

func (b *BaseError) AttrUint(key string) (uint, error)

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

func (b *BaseError) AttrUint64(key string) (uint64, error)

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

func (b *BaseError) Attrs() map[string]any

Attrs returns all of the attributes associated with the error.

If this object has no attributes defined, an empty map is returned.

func (*BaseError) Code added in v1.0.10

func (b *BaseError) Code() int

Code returns the error code.

func (*BaseError) Error added in v1.0.10

func (b *BaseError) Error() string

Error returns the corresponding error message.

func (*BaseError) InternalError added in v1.0.10

func (b *BaseError) InternalError() error

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

func (b *BaseError) NestedErrors() []Error

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.

func (*BaseError) WithAttr added in v1.1.0

func (b *BaseError) WithAttr(attrKey string, attrValue any) *BaseError

WithAttr adds the given key/value pair to the list of attributes associated with this error and returns itself

func (*BaseError) WithAttrs added in v1.1.0

func (b *BaseError) WithAttrs(attrs map[string]any) *BaseError

WithAttrs adds each of the given key/value pairs to the list of attributes associated with this error and returns itself.

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.

Jump to

Keyboard shortcuts

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