README.md

 1go-errors/errors
 2================
 3
 4[![Build Status](https://travis-ci.org/go-errors/errors.svg?branch=master)](https://travis-ci.org/go-errors/errors)
 5
 6Package errors adds stacktrace support to errors in go.
 7
 8This is particularly useful when you want to understand the state of execution
 9when an error was returned unexpectedly.
10
11It provides the type \*Error which implements the standard golang error
12interface, so you can use this library interchangably with code that is
13expecting a normal error return.
14
15Usage
16-----
17
18Full documentation is available on
19[godoc](https://godoc.org/github.com/go-errors/errors), but here's a simple
20example:
21
22```go
23package crashy
24
25import "github.com/go-errors/errors"
26
27var Crashed = errors.Errorf("oh dear")
28
29func Crash() error {
30    return errors.New(Crashed)
31}
32```
33
34This can be called as follows:
35
36```go
37package main
38
39import (
40    "crashy"
41    "fmt"
42    "github.com/go-errors/errors"
43)
44
45func main() {
46    err := crashy.Crash()
47    if err != nil {
48        if errors.Is(err, crashy.Crashed) {
49            fmt.Println(err.(*errors.Error).ErrorStack())
50        } else {
51            panic(err)
52        }
53    }
54}
55```
56
57Meta-fu
58-------
59
60This package was original written to allow reporting to
61[Bugsnag](https://bugsnag.com/) from
62[bugsnag-go](https://github.com/bugsnag/bugsnag-go), but after I found similar
63packages by Facebook and Dropbox, it was moved to one canonical location so
64everyone can benefit.
65
66This package is licensed under the MIT license, see LICENSE.MIT for details.