Skip to content

Commit e03971f

Browse files
jkowalskiJulio López
andauthored
Upgraded linter to v1.33.0 (kopia#734)
* linter: upgraded to 1.33, disabled some linters * lint: fixed 'errorlint' errors This ensures that all error comparisons use errors.Is() or errors.As(). We will be wrapping more errors going forward so it's important that error checks are not strict everywhere. Verified that there are no exceptions for errorlint linter which guarantees that. * lint: fixed or suppressed wrapcheck errors * lint: nolintlint and misc cleanups Co-authored-by: Julio López <[email protected]>
1 parent 246dcf8 commit e03971f

File tree

149 files changed

+533
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+533
-377
lines changed

.golangci.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ linters:
4444
- whitespace
4545
- nlreturn
4646
- testpackage
47+
- exhaustivestruct
48+
- paralleltest
49+
- tparallel
4750

4851
run:
4952
skip-dirs:
@@ -52,22 +55,24 @@ run:
5255
issues:
5356
exclude-use-default: false
5457
exclude-rules:
55-
- path: _test\.go|testing|test_env
58+
- path: _test\.go|testing|tests|test_env|fshasher
5659
linters:
5760
- gomnd
5861
- gocognit
5962
- funlen
6063
- errcheck
6164
- gosec
6265
- nestif
63-
- goerr113
66+
- wrapcheck
6467
- text: "Magic number: 1e"
6568
linters:
6669
- gomnd
6770
- text: "unnecessaryDefer"
68-
linters: gocritic
71+
linters:
72+
- gocritic
6973
- text: "filepathJoin"
70-
linters: gocritic
74+
linters:
75+
- gocritic
7176
- text: "weak cryptographic primitive"
7277
linters:
7378
- gosec
@@ -86,9 +91,3 @@ issues:
8691
- path: cli
8792
linters:
8893
- gochecknoglobals
89-
90-
# golangci.com configuration
91-
# https://github.com/golangci/golangci/wiki/Configuration
92-
service:
93-
golangci-lint-version: 1.24.x # use the fixed version to not introduce new linters unexpectedly
94-

cli/app.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ func maybeRunMaintenance(ctx context.Context, rep repo.Repository) error {
176176
return nil
177177
}
178178

179-
if _, ok := err.(maintenance.NotOwnedError); ok {
179+
var noe maintenance.NotOwnedError
180+
181+
if errors.As(err, &noe) {
180182
// do not report the NotOwnedError to the user since this is automatic maintenance.
181183
return nil
182184
}
183185

184-
return err
186+
return errors.Wrap(err, "error running maintenance")
185187
}
186188

187189
func advancedCommand(ctx context.Context) {

cli/command_benchmark_compression.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"io/ioutil"
88
"sort"
99

10+
"github.com/pkg/errors"
11+
1012
"github.com/kopia/kopia/internal/clock"
1113
"github.com/kopia/kopia/internal/units"
1214
"github.com/kopia/kopia/repo"
@@ -36,7 +38,7 @@ func runBenchmarkCompressionAction(ctx context.Context, rep repo.Repository) err
3638
if *benchmarkCompressionDataFile != "" {
3739
d, err := ioutil.ReadFile(*benchmarkCompressionDataFile)
3840
if err != nil {
39-
return err
41+
return errors.Wrap(err, "error reading compression data file")
4042
}
4143

4244
data = d

cli/command_benchmark_splitters.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"sort"
77
"time"
88

9+
"github.com/pkg/errors"
10+
911
"github.com/kopia/kopia/internal/clock"
1012
"github.com/kopia/kopia/repo"
1113
"github.com/kopia/kopia/repo/splitter"
@@ -42,7 +44,7 @@ func runBenchmarkSplitterAction(ctx context.Context, rep repo.Repository) error
4244
for i := 0; i < *benchmarkSplitterBlockCount; i++ {
4345
b := make([]byte, *benchmarkSplitterBlockSize)
4446
if _, err := rnd.Read(b); err != nil {
45-
return err
47+
return errors.Wrap(err, "error generating random data")
4648
}
4749

4850
dataBlocks = append(dataBlocks, b)

cli/command_blob_gc.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cli
33
import (
44
"context"
55

6+
"github.com/pkg/errors"
7+
68
"github.com/kopia/kopia/repo"
79
"github.com/kopia/kopia/repo/blob"
810
"github.com/kopia/kopia/repo/maintenance"
@@ -28,14 +30,14 @@ func runBlobGarbageCollectCommand(ctx context.Context, rep *repo.DirectRepositor
2830

2931
n, err := maintenance.DeleteUnreferencedBlobs(ctx, rep, opts)
3032
if err != nil {
31-
return err
33+
return errors.Wrap(err, "error deleting unreferenced blobs")
3234
}
3335

3436
if opts.DryRun && n > 0 {
3537
log(ctx).Infof("Pass --delete=yes to delete.")
3638
}
3739

38-
return err
40+
return nil
3941
}
4042

4143
func init() {

cli/command_blob_show.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ func maybeDecryptBlob(ctx context.Context, w io.Writer, rep *repo.DirectReposito
5656
return errors.Wrapf(err, "error getting %v", blobID)
5757
}
5858

59-
_, err = iocopy.Copy(w, bytes.NewReader(d))
59+
if _, err := iocopy.Copy(w, bytes.NewReader(d)); err != nil {
60+
return errors.Wrap(err, "error copying data")
61+
}
6062

61-
return err
63+
return nil
6264
}
6365

6466
func canDecryptBlob(b blob.ID) bool {

cli/command_blob_stats.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"strconv"
77

8+
"github.com/pkg/errors"
9+
810
"github.com/kopia/kopia/internal/units"
911
"github.com/kopia/kopia/repo"
1012
"github.com/kopia/kopia/repo/blob"
@@ -49,7 +51,7 @@ func runBlobStatsCommand(ctx context.Context, rep *repo.DirectRepository) error
4951
}
5052
return nil
5153
}); err != nil {
52-
return err
54+
return errors.Wrap(err, "error listing blobs")
5355
}
5456

5557
sizeToString := units.BytesStringBase10

cli/command_cache_clear.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func runCacheClearCommand(ctx context.Context, rep *repo.DirectRepository) error
2525
return os.RemoveAll(d)
2626
}, retry.Always)
2727
if err != nil {
28-
return err
28+
return errors.Wrap(err, "error removing cache directory")
2929
}
3030

3131
if err := os.MkdirAll(d, 0o700); err != nil {
32-
return err
32+
return errors.Wrap(err, "error creating cache directory")
3333
}
3434

3535
log(ctx).Infof("Cache cleared.")

cli/command_content_rm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cli
33
import (
44
"context"
55

6+
"github.com/pkg/errors"
7+
68
"github.com/kopia/kopia/repo"
79
)
810

@@ -17,7 +19,7 @@ func runContentRemoveCommand(ctx context.Context, rep *repo.DirectRepository) er
1719

1820
for _, contentID := range toContentIDs(*contentRemoveIDs) {
1921
if err := rep.Content.DeleteContent(ctx, contentID); err != nil {
20-
return err
22+
return errors.Wrapf(err, "error deleting content %v", contentID)
2123
}
2224
}
2325

cli/command_content_show.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"context"
66

7+
"github.com/pkg/errors"
8+
79
"github.com/kopia/kopia/repo"
810
"github.com/kopia/kopia/repo/content"
911
)
@@ -27,7 +29,7 @@ func runContentShowCommand(ctx context.Context, rep *repo.DirectRepository) erro
2729
func contentShow(ctx context.Context, r *repo.DirectRepository, contentID content.ID) error {
2830
data, err := r.Content.GetContent(ctx, contentID)
2931
if err != nil {
30-
return err
32+
return errors.Wrapf(err, "error getting content %v", contentID)
3133
}
3234

3335
return showContent(bytes.NewReader(data))

0 commit comments

Comments
 (0)