Categorygithub.com/xTransact/errx/v3
modulepackage
3.0.0
Repository: https://github.com/xtransact/errx.git
Documentation: pkg.go.dev

# README

errx

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

Quick Start

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

v3

v3 supports Error Code

Install

go get github.com/xTransact/errx/v3

Example

err := errx.WithCode(errcode.InternalServerError).New("failed to do something")
err = Wrap(err, "oops: :(")
err = Wrapf(err, "xxxxxxx")
fmt.Printf("%+v\n", err)

Result:

500: Internal Server Error: xxxxxxx: oops: :(: failed to do something
  Thrown: failed to do something
    --- at /home/xbank/go/pkg/errx/errx_test.go:17 TestCode1()
  Thrown: oops: :(
    --- at /home/xbank/go/pkg/errx/errx_test.go:18 TestCode1()
  Thrown: xxxxxxx
    --- at /home/xbank/go/pkg/errx/errx_test.go:19 TestCode1()

v2

v2 provides cleaner stacktrace.

Install

go get github.com/xTransact/errx/v2

Example

func a() error {
	return errx.Wrap(b(), "a()")
}

func b() error {
	return c()
}

func c() error {
	return d()
}

func d() error {
	return e()
}

func e() error {
	return f()
}

func f() error {
	return errx.Wrap(g(), "f()")
}

func g() error {
	return fmt.Errorf("nil pointer dereference")
}

func main() {
    err := a()
    err = Wrapf(err, "internal server error: %s", "xBank")
    fmt.Printf("%+v\n", err)
}

Result:

internal server error: xBank: a(): f(): nil pointer dereference
  Thrown: f()
    --- at /home/xbank/go/pkg/errx/errx_test.go:47 f()
  Thrown: a()
    --- at /home/xbank/go/pkg/errx/errx_test.go:27 a()
  Thrown: internal server error: xBank
    --- at /home/xbank/go/pkg/errx/errx_test.go:56 main()

v1

Install

go get github.com/xTransact/errx

Example

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()

# Packages

No description provided by the author

# Functions

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.
Cause returns the underlying cause of the error, if possible.
Errorf formats an error and returns `errx.Error` object that satisfies `error`.
No description provided by the author
No description provided by the author
No description provided by the author
Is reports whether any error in err's chain matches target.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error.
No description provided by the author
WithStack annotates err with a stack trace at the point WithStack was called.
Wrap wraps an error into an `errx.Error` object that satisfies `error`.
Wrapf wraps an error into an `errx.Error` object that satisfies `error` and formats an error message.

# Type aliases

No description provided by the author