errx

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 11 Imported by: 0

README

errx

errx is a more modern and convenient error handling library, providing more user-friendly stack information:

TestErrxWrap Failed: oops user: xBank: failed to check: xxx: something wrong.
Stacktrace:
  Error: something wrong.
    --- at /home/xbank/go/pkg/errx/errx_test.go:29 f()
    --- at /home/xbank/go/pkg/errx/errx_test.go:25 e()
    --- at /home/xbank/go/pkg/errx/errx_test.go:21 d()
    --- at /home/xbank/go/pkg/errx/errx_test.go:17 c()
    --- at /home/xbank/go/pkg/errx/errx_test.go:13 b()
  Thrown: xxx
    --- at /home/xbank/go/pkg/errx/errx_test.go:9 a()
    --- at /home/xbank/go/pkg/errx/errx_test.go:33 TestErrxWrap()
  Thrown: failed to check
    --- at /home/xbank/go/pkg/errx/errx_test.go:34 TestErrxWrap()
  Thrown: oops user: xBank
    --- at /home/xbank/go/pkg/errx/errx_test.go:35 TestErrxWrap()

Install

go get github.com/xTransact/errx

Quick Start

err := errx.New("oops: something wrong :(")
err = errx.Wrap(err, "failed to do something")
fmt.Printf("%+v\n", err)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SourceFragmentsHidden = true
View Source
var (
	StackTraceMaxDepth int = 15
)

Functions

func As

func As(err error, target any) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

func AsError

func AsError(err error) (xerr, bool)

func Errorf

func Errorf(format string, args ...any) error

Errorf formats an error and returns `errx.Error` object that satisfies `error`.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

func New

func New(message string) error

func Parse added in v1.0.1

func Parse(err error) error

Parse parses an error into an `errx.Error`.

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

func Wrap

func Wrap(err error, msg string) error

Wrap wraps an error into an `errx.Error` object that satisfies `error`

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf wraps an error into an `errx.Error` object that satisfies `error` and formats an error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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