errors

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 6 Imported by: 6

README

errors

Replacement for golang errors package.

Benchmarks

Take all benchmarks with a bucket of salt.

go test -bench=. -benchmem -count=1 -parallel 8 ./...

goos: linux
goarch: amd64
pkg: github.com/wspowell/errors
cpu: AMD Ryzen 9 4900HS with Radeon Graphics         
BenchmarkErrorsNew-8                    301735152                3.890 ns/op           0 B/op          0 allocs/op
BenchmarkErrorsWithStackTrace-8          1283198               929.4 ns/op           284 B/op          3 allocs/op
BenchmarkErrorsNewFmt-8                 16286179                69.42 ns/op            4 B/op          1 allocs/op
BenchmarkGoerrorsNew-8                  46670034                25.19 ns/op           16 B/op          1 allocs/op
BenchmarkGoerrorsWrap-8                  6644190               169.2 ns/op            36 B/op          2 allocs/op
BenchmarkErrorString-8                  1000000000               0.7221 ns/op          0 B/op          0 allocs/op
BenchmarkErrorStringWithStackTrace-8      416150              3012 ns/op             400 B/op          9 allocs/op
PASS
ok      github.com/wspowell/errors      11.682s

goos: linux
goarch: amd64
pkg: github.com/wspowell/errors/result
cpu: AMD Ryzen 9 4900HS with Radeon Graphics         
BenchmarkResultOkInt-8            328060              3646 ns/op               0 B/op          0 allocs/op
BenchmarkResultErrInt-8           326503              3643 ns/op               0 B/op          0 allocs/op
BenchmarkGoerrorOkInt-8           244785              4864 ns/op               0 B/op          0 allocs/op
BenchmarkGoerrorErrInt-8          501597              2488 ns/op               0 B/op          0 allocs/op
PASS
ok      github.com/wspowell/errors/result       4.987s

Documentation

Overview

Copied (and modified) from: github.com/pkg/errors@v0.9.1/stack.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithStackTrace added in v0.4.0

func WithStackTrace(ctx context.Context) context.Context

Types

type Error added in v0.4.0

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

Error keeps the context of the error to print later.

Error must be kept comparable.

func Catch added in v0.2.0

func Catch(ctx context.Context, fn func(ctx context.Context)) (err Error)

Catch potential panics that occur in a function call. Panics should never occur, therefore stack traces print regardless of build mode (release or debug). nolint:nonamedreturns // reason: need named return to alter the Error return in the defer

func New

func New(ctx context.Context, format string, values ...any) Error

New error. This should be called when the application creates a brand new error. If an error has been received from an external function, use Wrap().

func Recover added in v0.2.0

func Recover(ctx context.Context, errPanic any) Error

func (Error) Format added in v0.4.0

func (self Error) Format(state fmt.State, verb rune)

func (Error) IsNone added in v0.4.0

func (self Error) IsNone() bool

func (Error) String added in v0.4.0

func (self Error) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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