Skip to content
Yet another errors package, implementing error handling primitives.
Go Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml travis Jul 26, 2017
DCO
LICENSE
MAINTAINERS
Makefile
README.md
doc.go
error.go
error_test.go
example_test.go
matcher.go
matcher_test.go
stack.go Stacktrace and Causer interface (#3) Jan 17, 2017
stack_test.go

README.md

go-errors GoDoc Build Status codecov codebeat badge

Yet another errors package, implementing error handling primitives with error wrapping and error tracing.

Installation

The recommended way to install go-errors is:

go get -u gopkg.in/src-d/go-errors.v1

Examples

The Kind type allows you to create new errors containing the stack trace and also check if an error is of a particular kind.

var ErrExample = errors.NewKind("example")

err := ErrExample.New()
if ErrExample.Is(err) {
	fmt.Printf("%+v\n", err)
}

// Example Output:
// example
//
// gopkg.in/src-d/errors%2v0_test.ExampleError_Format
//         /home/mcuadros/workspace/go/src/gopkg.in/src-d/errors.v0/example_test.go:60
// testing.runExample
//         /usr/lib/go/src/testing/example.go:114
// testing.RunExamples
//         /usr/lib/go/src/testing/example.go:38
// testing.(*M).Run
//         /usr/lib/go/src/testing/testing.go:744
// main.main
//         github.com/pkg/errors/_test/_testmain.go:106
// runtime.main
//         /usr/lib/go/src/runtime/proc.go:183
// runtime.goexit
//         /usr/lib/go/src/runtime/asm_amd64.s:2086

Error with format

var ErrMaxLimitReached = errors.NewKind("max. limit reached: %d")

err := ErrMaxLimitReached.New(42)
if ErrMaxLimitReached.Is(err) {
    fmt.Println(err)
}

// Output: max. limit reached: 42

Error wrapping

var ErrNetworking = errors.NewKind("network error")

err := ErrNetworking.Wrap(io.EOF)
if ErrNetworking.Is(err) {
    fmt.Println(err)
}

// Output: network error: EOF

You can find these examples and many more in the examples file.

License

Apache License 2.0, see LICENSE

You can’t perform that action at this time.