Skip to content

Commit 27a59ff

Browse files
committed
lint: fix all golangci-lint issues and test failures
Fix gofmt formatting, simplify code patterns flagged by gocritic/staticcheck/revive, update test path expectations to not assume GOPATH layout. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent 18a238d commit 27a59ff

File tree

11 files changed

+136
-126
lines changed

11 files changed

+136
-126
lines changed

.golangci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ linters:
1212
default: standard
1313
enable:
1414
- bodyclose
15-
- errname
1615
- forbidigo
1716
- gocritic
1817
- gosec
@@ -25,3 +24,14 @@ linters:
2524
- unconvert
2625
- unparam
2726
- whitespace
27+
settings:
28+
errcheck:
29+
exclude-functions:
30+
- io.WriteString
31+
exclusions:
32+
presets:
33+
- std-error-handling
34+
rules:
35+
- linters:
36+
- gosec
37+
text: "G104"

bench_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.7
12
// +build go1.7
23

34
package errors
@@ -97,7 +98,7 @@ func BenchmarkStackFormatting(b *testing.B) {
9798
name := fmt.Sprintf("%s-stacktrace-%d", r.format, r.stack)
9899
b.Run(name, func(b *testing.B) {
99100
err := yesErrors(0, r.stack)
100-
st := err.(*fundamental).stack.StackTrace()
101+
st := err.(*fundamental).StackTrace()
101102
b.ReportAllocs()
102103
b.ResetTimer()
103104
for i := 0; i < b.N; i++ {

errors.go

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,89 @@
22
//
33
// The traditional error handling idiom in Go is roughly akin to
44
//
5-
// if err != nil {
6-
// return err
7-
// }
5+
// if err != nil {
6+
// return err
7+
// }
88
//
99
// which when applied recursively up the call stack results in error reports
1010
// without context or debugging information. The errors package allows
1111
// programmers to add context to the failure path in their code in a way
1212
// that does not destroy the original value of the error.
1313
//
14-
// Adding context to an error
14+
// # Adding context to an error
1515
//
1616
// The errors.Wrap function returns a new error that adds context to the
1717
// original error by recording a stack trace at the point Wrap is called,
1818
// together with the supplied message. For example
1919
//
20-
// _, err := ioutil.ReadAll(r)
21-
// if err != nil {
22-
// return errors.Wrap(err, "read failed")
23-
// }
20+
// _, err := io.ReadAll(r)
21+
// if err != nil {
22+
// return errors.Wrap(err, "read failed")
23+
// }
2424
//
2525
// If additional control is required, the errors.WithStack and
2626
// errors.WithMessage functions destructure errors.Wrap into its component
2727
// operations: annotating an error with a stack trace and with a message,
2828
// respectively.
2929
//
30-
// Retrieving the cause of an error
30+
// # Retrieving the cause of an error
3131
//
3232
// Using errors.Wrap constructs a stack of errors, adding context to the
3333
// preceding error. Depending on the nature of the error it may be necessary
3434
// to reverse the operation of errors.Wrap to retrieve the original error
3535
// for inspection. Any error value which implements this interface
3636
//
37-
// type causer interface {
38-
// Cause() error
39-
// }
37+
// type causer interface {
38+
// Cause() error
39+
// }
4040
//
4141
// can be inspected by errors.Cause. errors.Cause will recursively retrieve
4242
// the topmost error that does not implement causer, which is assumed to be
4343
// the original cause. For example:
4444
//
45-
// switch err := errors.Cause(err).(type) {
46-
// case *MyError:
47-
// // handle specifically
48-
// default:
49-
// // unknown error
50-
// }
45+
// switch err := errors.Cause(err).(type) {
46+
// case *MyError:
47+
// // handle specifically
48+
// default:
49+
// // unknown error
50+
// }
5151
//
5252
// Although the causer interface is not exported by this package, it is
5353
// considered a part of its stable public interface.
5454
//
55-
// Formatted printing of errors
55+
// # Formatted printing of errors
5656
//
5757
// All error values returned from this package implement fmt.Formatter and can
5858
// be formatted by the fmt package. The following verbs are supported:
5959
//
60-
// %s print the error. If the error has a Cause it will be
61-
// printed recursively.
62-
// %v see %s
63-
// %+v extended format. Each Frame of the error's StackTrace will
64-
// be printed in detail.
60+
// %s print the error. If the error has a Cause it will be
61+
// printed recursively.
62+
// %v see %s
63+
// %+v extended format. Each Frame of the error's StackTrace will
64+
// be printed in detail.
6565
//
66-
// Retrieving the stack trace of an error or wrapper
66+
// # Retrieving the stack trace of an error or wrapper
6767
//
6868
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
6969
// invoked. This information can be retrieved with the following interface:
7070
//
71-
// type stackTracer interface {
72-
// StackTrace() errors.StackTrace
73-
// }
71+
// type stackTracer interface {
72+
// StackTrace() errors.StackTrace
73+
// }
7474
//
7575
// The returned errors.StackTrace type is defined as
7676
//
77-
// type StackTrace []Frame
77+
// type StackTrace []Frame
7878
//
7979
// The Frame type represents a call site in the stack trace. Frame supports
8080
// the fmt.Formatter interface that can be used for printing information about
8181
// the stack trace of this error. For example:
8282
//
83-
// if err, ok := err.(stackTracer); ok {
84-
// for _, f := range err.StackTrace() {
85-
// fmt.Printf("%+s:%d\n", f, f)
86-
// }
87-
// }
83+
// if err, ok := err.(stackTracer); ok {
84+
// for _, f := range err.StackTrace() {
85+
// fmt.Printf("%+s:%d\n", f, f)
86+
// }
87+
// }
8888
//
8989
// Although the stackTracer interface is not exported by this package, it is
9090
// considered a part of its stable public interface.
@@ -265,13 +265,18 @@ func (w *withMessage) Format(s fmt.State, verb rune) {
265265
// An error value has a cause if it implements the following
266266
// interface:
267267
//
268-
// type causer interface {
269-
// Cause() error
270-
// }
268+
// type causer interface {
269+
// Cause() error
270+
// }
271271
//
272272
// If the error does not implement Cause, the original error will
273273
// be returned. If the error is nil, nil will be returned without further
274274
// investigation.
275+
//
276+
// Note: Cause only traverses errors implementing the causer interface.
277+
// It does not traverse errors wrapped with fmt.Errorf("%w", err) or
278+
// other standard library mechanisms. Prefer errors.Is or errors.As
279+
// for matching errors across mixed wrapping styles.
275280
func Cause(err error) error {
276281
type causer interface {
277282
Cause() error

errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func TestWithMessagef(t *testing.T) {
228228
// but the change in errors#27 made them incomparable. Assert that
229229
// various kinds of errors have a functional equality operator, even
230230
// if the result of that equality is always false.
231-
func TestErrorEquality(t *testing.T) {
231+
func TestErrorEquality(_ *testing.T) {
232232
vals := []error{
233233
nil,
234234
io.EOF,

0 commit comments

Comments
 (0)