Skip to content

Commit d409df3

Browse files
committed
feat: add ignorePackageGlobs configuration
1 parent ae2ca99 commit d409df3

File tree

25 files changed

+2396
-19
lines changed

25 files changed

+2396
-19
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ ignoreSigs:
3737
- .WithMessage(
3838
- .WithMessagef(
3939
- .WithStack(
40+
41+
# An array of glob patterns which, if any match the package of the function
42+
# returning the error, will skip wrapcheck analysis for this error. This is
43+
# useful for broadly ignoring packages and/or subpackages from wrapcheck
44+
# analysis. There are no defaults for this value.
45+
ignorePackageGlobs:
46+
- encoding/*
47+
- github.com/pkg/*
4048
```
4149
4250
## Usage

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/tomarrell/wrapcheck/v2
33
go 1.16
44

55
require (
6+
github.com/gobwas/glob v0.2.3
67
github.com/spf13/viper v1.7.1
78
github.com/stretchr/testify v1.6.1
89
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
4545
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
4646
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
4747
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
48+
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
49+
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
4850
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
4951
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
5052
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignorePackageGlobs:
2+
- "encoding/*"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignoreSigs:
2+
ignorePackageGlobs:
3+
- github.com/pkg/*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/pkg/errors"
8+
)
9+
10+
func main() {
11+
do()
12+
}
13+
14+
func do() error {
15+
err := fmt.Errorf("failed to do something")
16+
if err != nil {
17+
return errors.Wrap(err, "uh oh")
18+
}
19+
20+
if err != nil {
21+
return errors.Wrapf(err, "uh oh")
22+
}
23+
24+
if err != nil {
25+
return errors.WithMessage(err, "uh oh")
26+
}
27+
28+
if err != nil {
29+
return errors.WithMessagef(err, "uh %s", "oh")
30+
}
31+
32+
if err != nil {
33+
return errors.WithStack(err)
34+
}
35+
36+
_, err = json.Marshal(struct{}{})
37+
if err != nil {
38+
return err // want `error returned from external package is unwrapped`
39+
}
40+
41+
return errors.New("uh oh")
42+
}
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PKGS := github.com/pkg/errors
2+
SRCDIRS := $(shell go list -f '{{.Dir}}' $(PKGS))
3+
GO := go
4+
5+
check: test vet gofmt misspell unconvert staticcheck ineffassign unparam
6+
7+
test:
8+
$(GO) test $(PKGS)
9+
10+
vet: | test
11+
$(GO) vet $(PKGS)
12+
13+
staticcheck:
14+
$(GO) get honnef.co/go/tools/cmd/staticcheck
15+
staticcheck -checks all $(PKGS)
16+
17+
misspell:
18+
$(GO) get github.com/client9/misspell/cmd/misspell
19+
misspell \
20+
-locale GB \
21+
-error \
22+
*.md *.go
23+
24+
unconvert:
25+
$(GO) get github.com/mdempsky/unconvert
26+
unconvert -v $(PKGS)
27+
28+
ineffassign:
29+
$(GO) get github.com/gordonklaus/ineffassign
30+
find $(SRCDIRS) -name '*.go' | xargs ineffassign
31+
32+
pedantic: check errcheck
33+
34+
unparam:
35+
$(GO) get mvdan.cc/unparam
36+
unparam ./...
37+
38+
errcheck:
39+
$(GO) get github.com/kisielk/errcheck
40+
errcheck $(PKGS)
41+
42+
gofmt:
43+
@echo Checking code is gofmted
44+
@test -z "$(shell gofmt -s -l -d -e $(SRCDIRS) | tee /dev/stderr)"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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) [![Sourcegraph](https://sourcegraph.com/github.com/pkg/errors/-/badge.svg)](https://sourcegraph.com/github.com/pkg/errors?badge)
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+
## Roadmap
45+
46+
With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows:
47+
48+
- 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible)
49+
- 1.0. Final release.
50+
51+
## Contributing
52+
53+
Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports.
54+
55+
Before sending a PR, please discuss your change by raising an issue.
56+
57+
## License
58+
59+
BSD-2-Clause

0 commit comments

Comments
 (0)