Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit e8426bf

Browse files
committed
[update-vendor] add github.com/pkg/errors to vendor
1 parent 9dc2d0c commit e8426bf

File tree

10 files changed

+1863
-0
lines changed

10 files changed

+1863
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2015, Dave Cheney <dave@cheney.net>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors)
2+
3+
Package errors provides simple error handling primitives.
4+
5+
`go get github.com/pkg/errors`
6+
7+
The traditional error handling idiom in Go is roughly akin to
8+
```go
9+
if err != nil {
10+
return err
11+
}
12+
```
13+
which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
14+
15+
## Adding context to an error
16+
17+
The errors.Wrap function returns a new error that adds context to the original error. For example
18+
```go
19+
_, err := ioutil.ReadAll(r)
20+
if err != nil {
21+
return errors.Wrap(err, "read failed")
22+
}
23+
```
24+
## Retrieving the cause of an error
25+
26+
Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
27+
```go
28+
type causer interface {
29+
Cause() error
30+
}
31+
```
32+
`errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
33+
```go
34+
switch err := errors.Cause(err).(type) {
35+
case *MyError:
36+
// handle specifically
37+
default:
38+
// unknown error
39+
}
40+
```
41+
42+
[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
43+
44+
## Contributing
45+
46+
We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high.
47+
48+
Before proposing a change, please discuss your change by raising an issue.
49+
50+
## Licence
51+
52+
BSD-2-Clause
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// +build go1.7
2+
3+
package errors
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
stderrors "errors"
10+
)
11+
12+
func noErrors(at, depth int) error {
13+
if at >= depth {
14+
return stderrors.New("no error")
15+
}
16+
return noErrors(at+1, depth)
17+
}
18+
func yesErrors(at, depth int) error {
19+
if at >= depth {
20+
return New("ye error")
21+
}
22+
return yesErrors(at+1, depth)
23+
}
24+
25+
func BenchmarkErrors(b *testing.B) {
26+
var toperr error
27+
type run struct {
28+
stack int
29+
std bool
30+
}
31+
runs := []run{
32+
{10, false},
33+
{10, true},
34+
{100, false},
35+
{100, true},
36+
{1000, false},
37+
{1000, true},
38+
}
39+
for _, r := range runs {
40+
part := "pkg/errors"
41+
if r.std {
42+
part = "errors"
43+
}
44+
name := fmt.Sprintf("%s-stack-%d", part, r.stack)
45+
b.Run(name, func(b *testing.B) {
46+
var err error
47+
f := yesErrors
48+
if r.std {
49+
f = noErrors
50+
}
51+
b.ReportAllocs()
52+
for i := 0; i < b.N; i++ {
53+
err = f(0, r.stack)
54+
}
55+
b.StopTimer()
56+
toperr = err
57+
})
58+
}
59+
}

0 commit comments

Comments
 (0)