errx

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

README

errx

Go Report Card GitHub license codecov

Traceable Error Wrapper for Golang

Installing

go get github.com/nbs-go/errx

Example

TODO

Contributors

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DuplicateFallbackError = NewError("ERR_1", "Cannot create new Error that has same code with Fallback Error",
	WithNamespace(pkgNamespace))

Functions

func Trace added in v0.2.1

func Trace(err error) error

Trace wrap and trace error. If error is not *errx.Error then it will be wrapped into InternalError Else, it will add stack trace to error

Types

type Builder

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

Builder is an error builder with template namespace. All error produced will have a namespace

func NewBuilder

func NewBuilder(namespace string, args ...SetOptionFn) *Builder

func (*Builder) CopyError added in v0.2.0

func (b *Builder) CopyError(err *Error, args ...SetOptionFn) *Error

CopyError take error input and override the namespace

func (*Builder) FallbackError

func (b *Builder) FallbackError() *Error

FallbackError is getter function to retrieve FallbackError value

func (*Builder) Get

func (b *Builder) Get(code string) *Error

Get retrieve error by Code, if no t exist then return fallback error

func (*Builder) Namespace

func (b *Builder) Namespace() string

Namespace is getter function to retrieve builder namespace

func (*Builder) NewError

func (b *Builder) NewError(code string, message string, args ...SetOptionFn) *Error

NewError create new error and ensure error is unique by it's code

type Error

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

Error is an immutable object. print error meaningful message and stack trace for easier error tracing

func InternalError

func InternalError() *Error

func NewError

func NewError(code string, message string, args ...SetOptionFn) *Error

NewError initiates a new error instance

func Wrap

func Wrap(err error) *Error

func (*Error) AddMetadata added in v0.5.0

func (e *Error) AddMetadata(key string, value interface{}) *Error

AddMetadata copy existing error and set new metadata

func (*Error) Code

func (e *Error) Code() string

Code is getter function to retrieve error code value

func (*Error) Copy

func (e *Error) Copy(args ...SetOptionFn) *Error

Copy duplicate error traces. Available options is WithNamespace, WithMetadata and CopySource

func (*Error) Error

func (e *Error) Error() string

Error implement standard go error interface. If source error is exists then it will print error cause

func (*Error) Is

func (e *Error) Is(err error) bool

Is implements function that will be called by errors.Is for error comparison. Actual error namespace and code value must equal with Expected ones

func (*Error) Message added in v0.4.0

func (e *Error) Message() string

Message is getter function to retrieve message value

func (*Error) Metadata

func (e *Error) Metadata() map[string]interface{}

Metadata is getter function to retrieve metadata value

func (*Error) Namespace

func (e *Error) Namespace() string

Namespace is getter function to retrieve error namespace

func (*Error) Trace

func (e *Error) Trace(args ...SetOptionFn) *Error

func (*Error) Traces

func (e *Error) Traces() []string

Traces is getter function to retrieve traces value

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements xerrors.Wrapper interface

func (*Error) Wrap

func (e *Error) Wrap(err error) *Error

type SetOptionFn

type SetOptionFn = func(*options)

func AddMetadata added in v0.2.0

func AddMetadata(key string, value interface{}) SetOptionFn

func Errorf added in v0.3.0

func Errorf(msg string, args ...interface{}) SetOptionFn

func FallbackError

func FallbackError(err *Error) SetOptionFn

func SkipTrace

func SkipTrace(skip int) SetOptionFn

func Source added in v0.2.1

func Source(err error) SetOptionFn

func WithMetadata

func WithMetadata(metadata map[string]interface{}) SetOptionFn

func WithNamespace

func WithNamespace(namespace string) SetOptionFn

Jump to

Keyboard shortcuts

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