Skip to content

Commit

Permalink
fix subset of errors import and replace Cause with Is and As mostly
Browse files Browse the repository at this point in the history
Signed-off-by: Bisakh Mondal <[email protected]>
  • Loading branch information
bisakhmondal committed Mar 17, 2022
1 parent 12d2ef0 commit cbf85c7
Show file tree
Hide file tree
Showing 26 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/runutil"
)
Expand Down
22 changes: 11 additions & 11 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/go-kit/log/level"
"github.com/golang/groupcache/singleflight"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/model/labels"
Expand All @@ -27,6 +26,7 @@ import (
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/errutil"
"github.com/thanos-io/thanos/pkg/extprom"
"github.com/thanos-io/thanos/pkg/model"
Expand Down Expand Up @@ -328,20 +328,20 @@ func (f *BaseFetcher) fetchMetadata(ctx context.Context) (interface{}, error) {
continue
}

switch errors.Cause(err) {
default:
mtx.Lock()
resp.metaErrs.Add(err)
mtx.Unlock()
continue
case ErrorSyncMetaNotFound:
switch {
case errors.Is(err, ErrorSyncMetaNotFound):
mtx.Lock()
resp.noMetas++
mtx.Unlock()
case ErrorSyncMetaCorrupted:
case errors.Is(err, ErrorSyncMetaCorrupted):
mtx.Lock()
resp.corruptedMetas++
mtx.Unlock()
default:
mtx.Lock()
resp.metaErrs.Add(err)
mtx.Unlock()
continue
}

mtx.Lock()
Expand Down Expand Up @@ -832,10 +832,10 @@ func (f *IgnoreDeletionMarkFilter) Filter(ctx context.Context, metas map[ulid.UL
for id := range ch {
m := &metadata.DeletionMark{}
if err := metadata.ReadMarker(ctx, f.logger, f.bkt, id.String(), m); err != nil {
if errors.Cause(err) == metadata.ErrorMarkerNotFound {
if errors.Is(err, metadata.ErrorMarkerNotFound) {
continue
}
if errors.Cause(err) == metadata.ErrorUnmarshalMarker {
if errors.Is(err, metadata.ErrorUnmarshalMarker) {
level.Warn(f.logger).Log("msg", "found partial deletion-mark.json; if we will see it happening often for the same block, consider manually deleting deletion-mark.json from the object storage", "block", id, "err", err)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/block/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/tsdb/chunks"
"github.com/prometheus/prometheus/tsdb/index"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/runutil"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/block/metadata/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"path/filepath"

"github.com/go-kit/log"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/runutil"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/block/metadata/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/go-kit/log"
"github.com/oklog/ulid"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/runutil"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/block/metadata/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/go-kit/log"
"github.com/oklog/ulid"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/promql/parser"
Expand All @@ -26,6 +25,7 @@ import (
"github.com/prometheus/prometheus/tsdb/tombstones"
"gopkg.in/yaml.v3"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/runutil"
)

Expand Down
10 changes: 6 additions & 4 deletions pkg/discovery/dns/godns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package godns
import (
"net"

"github.com/pkg/errors"
"github.com/thanos-io/thanos/pkg/errors"
)

// Resolver is a wrapper for net.Resolver.
Expand All @@ -19,7 +19,9 @@ func (r *Resolver) IsNotFound(err error) bool {
if err == nil {
return false
}
err = errors.Cause(err)
dnsErr, ok := err.(*net.DNSError)
return ok && dnsErr.IsNotFound
dnsErr := new(net.DNSError)
if errors.As(err, dnsErr) {
return dnsErr.IsNotFound
}
return false
}
3 changes: 2 additions & 1 deletion pkg/discovery/dns/miekgdns/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"net"

"github.com/miekg/dns"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
)

var ErrNoSuchHost = errors.New("no such host")
Expand Down
5 changes: 3 additions & 2 deletions pkg/discovery/dns/miekgdns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"net"

"github.com/miekg/dns"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
)

// DefaultResolvConfPath is a common, default resolv.conf file present on linux server.
Expand Down Expand Up @@ -74,5 +75,5 @@ func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr,
}

func (r *Resolver) IsNotFound(err error) bool {
return errors.Is(errors.Cause(err), ErrNoSuchHost)
return errors.Is(err, ErrNoSuchHost)
}
2 changes: 1 addition & 1 deletion pkg/discovery/dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"

"github.com/pkg/errors"
"github.com/thanos-io/thanos/pkg/errors"
)

type QType string
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
blob "github.com/Azure/azure-storage-blob-go/azblob"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
)

Expand Down
5 changes: 3 additions & 2 deletions pkg/objstore/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"context"
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/runutil"
)
Expand Down Expand Up @@ -232,7 +233,7 @@ func (b *Bucket) Delete(_ context.Context, name string) error {

// IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.
func (b *Bucket) IsObjNotFoundErr(err error) bool {
return os.IsNotExist(errors.Cause(err))
return errors.Is(err, fs.ErrNotExist)
}

func (b *Bucket) Close() error { return nil }
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (

"cloud.google.com/go/storage"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/common/version"
"golang.org/x/oauth2/google"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sync"
"time"

"github.com/pkg/errors"
"github.com/thanos-io/thanos/pkg/errors"
)

var errNotFound = errors.New("inmem: object not found")
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/runutil"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/objstore/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/encrypt"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/runutil"
)
Expand Down Expand Up @@ -523,7 +523,7 @@ func (b *Bucket) Delete(ctx context.Context, name string) error {

// IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.
func (b *Bucket) IsObjNotFoundErr(err error) bool {
return minio.ToErrorResponse(errors.Cause(err)).Code == "NoSuchKey"
return minio.ToErrorResponse(errors.UnwrapTillCause(err)).Code == "NoSuchKey"
}

func (b *Bucket) Close() error { return nil }
Expand Down
3 changes: 2 additions & 1 deletion pkg/objstore/s3/s3_aws_sdk_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
aws "github.com/aws/aws-sdk-go-v2/aws"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
)

// AWSSDKAuth retrieves credentials from the aws-sdk-go.
Expand Down
2 changes: 1 addition & 1 deletion pkg/objstore/swift/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/ncw/swift"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/runutil"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runutil/runutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/errutil"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/targets/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"github.com/go-kit/log"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/store/labelpb"
Expand Down
3 changes: 2 additions & 1 deletion pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
"github.com/pmezard/go-difflib/difflib"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
Expand All @@ -25,6 +24,8 @@ import (
"github.com/prometheus/prometheus/tsdb/chunks"
"github.com/prometheus/prometheus/tsdb/index"
"go.uber.org/goleak"

"github.com/thanos-io/thanos/pkg/errors"
)

// Assert fails the test if the condition is false.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/exemplars_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"time"

"github.com/efficientgo/e2e"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/timestamp"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/exemplars/exemplarspb"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/testutil"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

"github.com/efficientgo/e2e"
"github.com/efficientgo/e2e/matchers"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/timestamp"

"github.com/thanos-io/thanos/pkg/cacheutil"
"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/queryfrontend"
"github.com/thanos-io/thanos/pkg/testutil"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
"github.com/chromedp/chromedp"
"github.com/efficientgo/e2e"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/timestamp"
"github.com/prometheus/prometheus/rules"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/exemplars/exemplarspb"
"github.com/thanos-io/thanos/pkg/metadata/metadatapb"
"github.com/thanos-io/thanos/pkg/objstore"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/rules_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

"github.com/efficientgo/e2e"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/rules"

"github.com/thanos-io/thanos/pkg/httpconfig"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/rules/rulespb"
"github.com/thanos-io/thanos/pkg/runutil"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/targets_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/efficientgo/e2e"
"github.com/go-kit/log"
"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/errors"
"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/store/labelpb"
Expand Down

0 comments on commit cbf85c7

Please sign in to comment.