errorz

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 4 Imported by: 1

README

gopherz

ezpkg.io/errorz

PkgGoDev GitHub License version

Package errorz provides functions for dealing with errors, with stacktrace, validation, and multi-errors.

Installation

go get -u ezpkg.io/errorz@v0.0.7

Examples

Must
data := errorz.Must(os.ReadFile(path))
fmt.Printf("%s", data)

errorz.MustZ(os.WriteFile(path, data, 0644))
Stacktrace
err := fmt.Errorf("foo")
zErr := errorz.Wrapf(err, "bar/%v", "one")

fmt.Printf("%v\n", zErr)
// bar/one: foo

fmt.Printf("%+v\n", zErr)
// bar/one: foo
// ezpkg.io/errorz_test.TestError.func1
// /Users/i/ws/ezpkg/ezpkg/errorz/errorz_test.go:12
// testing.tRunner
// /usr/local/go/src/testing/testing.go:7890

fmt.Printf("%#v\n", zErr)
// bar/one: foo
// ezpkg.io/errorz_test/errorz_test.go:12 · TestError.func1
// testing/testing.go:7890 · tRunner
No stacktrace
zErr := errorz.NoStack().New("no stack")
fmt.Printf("%+v", zErr)
Multi-errors
var err error
errorz.AppendTo(&err, fmt.Errorf("foo"))
errorz.AppendTo(&err, nil)
fmt.Printf("%+v", err)

var err2 error
err2 = errorz.Append(err2, err)
fmt.Printf("%+v", err2)

Similar Packages

About ezpkg.io

As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created this repository to have all these utilities and packages in one place. Hopefully, you'll find them useful as well.

For more information, see the main repository.

Author

Oliver Nguyen  github

Documentation

Index

Constants

View Source
const ZzVersion = `0.0.7`

internal usage

Variables

This section is empty.

Functions

func Append

func Append(err0 error, errs ...error) error

func AppendTo

func AppendTo(pErr *error, errs ...error)

func AppendTof

func AppendTof(pErr *error, err error, msg string, args ...any)

func Appendf

func Appendf(err0 error, err error, msg string, args ...any) error

func Error

func Error(msg string) error

func Errorf

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

func GetErrors

func GetErrors(err error) []error

func Must

func Must[T any](v T, err error) T

func Must2 added in v0.0.7

func Must2[A, B any](a A, b B, err error) (A, B)

func Must3 added in v0.0.7

func Must3[A, B, C any](a A, b B, c C, err error) (A, B, C)

func Must4 added in v0.0.7

func Must4[A, B, C, D any](a A, b B, c C, d D, err error) (A, B, C, D)

func Must5 added in v0.0.7

func Must5[A, B, C, D, E any](a A, b B, c C, d D, e E, err error) (A, B, C, D, E)

func Must6 added in v0.0.7

func Must6[A, B, C, D, E, F any](a A, b B, c C, d D, e E, f F, err error) (A, B, C, D, E, F)

func Must7 added in v0.0.7

func Must7[A, B, C, D, E, F, G any](a A, b B, c C, d D, e E, f F, g G, err error) (A, B, C, D, E, F, G)

func Must8 added in v0.0.7

func Must8[A, B, C, D, E, F, G, H any](a A, b B, c C, d D, e E, f F, g G, h H, err error) (A, B, C, D, E, F, G, H)

func MustZ

func MustZ(err error)

func New

func New(msg string) error

func Newf

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

func Skip added in v0.0.7

func Skip[T any](v T, _ error) T

func Skip2 added in v0.0.7

func Skip2[A, B any](a A, b B, _ error) (A, B)

func Skip3 added in v0.0.7

func Skip3[A, B, C any](a A, b B, c C, _ error) (A, B, C)

func Skip4 added in v0.0.7

func Skip4[A, B, C, D any](a A, b B, c C, d D, _ error) (A, B, C, D)

func Skip5 added in v0.0.7

func Skip5[A, B, C, D, E any](a A, b B, c C, d D, e E, _ error) (A, B, C, D, E)

func Skip6 added in v0.0.7

func Skip6[A, B, C, D, E, F any](a A, b B, c C, d D, e E, f F, _ error) (A, B, C, D, E, F)

func Skip7 added in v0.0.7

func Skip7[A, B, C, D, E, F, G any](a A, b B, c C, d D, e E, f F, g G, _ error) (A, B, C, D, E, F, G)

func Skip8 added in v0.0.7

func Skip8[A, B, C, D, E, F, G, H any](a A, b B, c C, d D, e E, f F, g G, h H, _ error) (A, B, C, D, E, F, G, H)

func SkipZ added in v0.0.7

func SkipZ(_ error)

func ValidateX

func ValidateX[T any](pErr *error, value T, condition bool, msg string, args ...any) (out T)

func Validatef

func Validatef(pErr *error, condition bool, msg string, args ...any)

func Wrap

func Wrap(err error, msg string) error

func Wrapf

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

Types

type Errors

type Errors interface {
	error
	Errors() []error
}

type Option

type Option struct {
	NoStack     bool
	CallersSkip int
}

func CallersSkip

func CallersSkip(n int) Option

func NoStack

func NoStack() Option

func (Option) Append

func (opt Option) Append(pErr *error, errs ...error)

func (Option) Appendf

func (opt Option) Appendf(pErr *error, err error, msgArgs ...any)

func (Option) Error

func (opt Option) Error(msg string) error

func (Option) Errorf

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

func (Option) New

func (opt Option) New(msg string) error

func (Option) Newf

func (opt Option) Newf(format string, args ...any) error

func (Option) Wrap

func (opt Option) Wrap(err error, msg string) error

func (Option) Wrapf

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

Jump to

Keyboard shortcuts

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