...

Text file src/github.com/go-errors/errors/README.md

Documentation: github.com/go-errors/errors

     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 interchangeably 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.
    67
    68
    69## Changelog
    70* v1.1.0 updated to use go1.13's standard-library errors.Is method instead of == in errors.Is
    71* v1.2.0 added `errors.As` from the standard library.
    72* v1.3.0 *BREAKING* updated error methods to return `error` instead of `*Error`.
    73>  Code that needs access to the underlying `*Error` can use the new errors.AsError(e)
    74> ```
    75>   // before
    76>   errors.New(err).ErrorStack()
    77>   // after
    78>.  errors.AsError(errors.Wrap(err)).ErrorStack()
    79> ```
    80* v1.4.0 *BREAKING* v1.4.0 reverted all changes from v1.3.0 and is identical to v1.2.0
    81* v1.4.1 no code change, but now without an unnecessary cover.out file.
    82* v1.4.2 performance improvement to ErrorStack() to avoid unnecessary work https://github.com/go-errors/errors/pull/40
    83* v1.5.0 add errors.Join() and errors.Unwrap() copying the stdlib https://github.com/go-errors/errors/pull/40
    84* v1.5.1 fix build on go1.13..go1.19 (broken by adding Join and Unwrap with wrong build constraints)

View as plain text