From d8dcae3075d2425e351f76a740b55531313b3c8f Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 16 Jul 2020 18:50:15 +0300 Subject: [PATCH] all: fix error checking Change-Id: Ia0da1bbd6ce695139922f94096c2419281905e32 --- cmd/storagenode/gracefulexit.go | 2 +- satellite/console/service.go | 3 ++- satellite/repair/repairer/ec.go | 7 ++++--- satellite/satellitedb/heldamount.go | 5 +++-- satellite/satellitedb/projectaccounting.go | 4 ++-- storage/cockroachkv/client.go | 4 ++-- storage/cockroachkv/ordered_iterator.go | 3 ++- storage/postgreskv/ordered_iterator.go | 3 ++- storagenode/gracefulexit/blobscleaner.go | 3 ++- storagenode/heldamount/service.go | 3 ++- storagenode/storagenodedb/heldamount.go | 5 +++-- 11 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cmd/storagenode/gracefulexit.go b/cmd/storagenode/gracefulexit.go index 81aa1d000..2f0f7ddbf 100644 --- a/cmd/storagenode/gracefulexit.go +++ b/cmd/storagenode/gracefulexit.go @@ -122,7 +122,7 @@ func cmdGracefulExitInit(cmd *cobra.Command, args []string) error { selectedSatellite = append(selectedSatellite, inputs...) break } - if err != scanner.Err() || err != nil { + if err != scanner.Err() || err != nil { //nolint: goerr113 return errs.Wrap(err) } diff --git a/satellite/console/service.go b/satellite/console/service.go index 527bb80b3..19c7dde7c 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -7,6 +7,7 @@ import ( "context" "crypto/subtle" "database/sql" + "errors" "fmt" "sort" "time" @@ -472,7 +473,7 @@ func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret R if err == nil { return nil, ErrEmailUsed.New(emailUsedErrMsg) } - if err != sql.ErrNoRows { + if !errors.Is(err, sql.ErrNoRows) { return nil, Error.Wrap(err) } diff --git a/satellite/repair/repairer/ec.go b/satellite/repair/repairer/ec.go index af8cd57c4..b040d1e0d 100644 --- a/satellite/repair/repairer/ec.go +++ b/satellite/repair/repairer/ec.go @@ -6,6 +6,7 @@ package repairer import ( "bytes" "context" + "errors" "io" "io/ioutil" "sort" @@ -327,7 +328,7 @@ func (ec *ECRepairer) Repair(ctx context.Context, limits []*pb.AddressedOrderLim var successfulCount, failureCount, cancellationCount int32 timer := time.AfterFunc(timeout, func() { - if ctx.Err() != context.Canceled { + if !errors.Is(ctx.Err(), context.Canceled) { ec.log.Debug("Timer expired. Canceling the long tail...", zap.Int32("Successfully repaired", atomic.LoadInt32(&successfulCount)), ) @@ -459,8 +460,8 @@ func (ec *ECRepairer) putPiece(ctx, parent context.Context, limit *pb.AddressedO _, err = sync2.Copy(ctx, upload, data) // Canceled context means the piece upload was interrupted by user or due // to slow connection. No error logging for this case. - if ctx.Err() == context.Canceled { - if parent.Err() == context.Canceled { + if errors.Is(ctx.Err(), context.Canceled) { + if errors.Is(parent.Err(), context.Canceled) { ec.log.Debug("Upload to node canceled by user", zap.Stringer("Node ID", storageNodeID)) } else { diff --git a/satellite/satellitedb/heldamount.go b/satellite/satellitedb/heldamount.go index c5993ea2c..39e5cd5fd 100644 --- a/satellite/satellitedb/heldamount.go +++ b/satellite/satellitedb/heldamount.go @@ -6,6 +6,7 @@ package satellitedb import ( "context" "database/sql" + "errors" "github.com/zeebo/errs" @@ -50,7 +51,7 @@ func (paystubs *paymentStubs) GetPaystub(ctx context.Context, nodeID storj.NodeI &payStub.Paid, ) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { return heldamount.PayStub{}, heldamount.ErrNoDataForPeriod.Wrap(err) } @@ -151,7 +152,7 @@ func (paystubs *paymentStubs) GetPayment(ctx context.Context, nodeID storj.NodeI &payment.Notes, ) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { return heldamount.StoragenodePayment{}, heldamount.ErrNoDataForPeriod.Wrap(err) } diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index a1c4e5906..66b128ca9 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -579,7 +579,7 @@ func (db *ProjectAccounting) GetBucketTotals(ctx context.Context, projectID uuid var egress int64 err = rollupRow.Scan(&egress) if err != nil { - if err != sql.ErrNoRows { + if !errors.Is(err, sql.ErrNoRows) { return nil, err } } @@ -591,7 +591,7 @@ func (db *ProjectAccounting) GetBucketTotals(ctx context.Context, projectID uuid var inline, remote, objectCount int64 err = storageRow.Scan(&inline, &remote, &objectCount) if err != nil { - if err != sql.ErrNoRows { + if !errors.Is(err, sql.ErrNoRows) { return nil, err } } diff --git a/storage/cockroachkv/client.go b/storage/cockroachkv/client.go index 6bd08d260..27b9298e1 100644 --- a/storage/cockroachkv/client.go +++ b/storage/cockroachkv/client.go @@ -143,7 +143,7 @@ func (client *Client) getAllOnce(ctx context.Context, keys storage.Keys) (values } defer func() { closeErr := rows.Close() - if closeErr != nil && closeErr != err { + if closeErr != nil && closeErr != err { //nolint: goerr113 err = errs.Combine(err, closeErr) } }() @@ -218,7 +218,7 @@ func (client *Client) deleteMultipleOnce(ctx context.Context, keys storage.Keys) } defer func() { closeErr := rows.Close() - if closeErr != nil && closeErr != err { + if closeErr != nil && closeErr != err { //nolint: goerr113 err = errs.Combine(err, closeErr) } }() diff --git a/storage/cockroachkv/ordered_iterator.go b/storage/cockroachkv/ordered_iterator.go index 4c899684a..25a3abcaf 100644 --- a/storage/cockroachkv/ordered_iterator.go +++ b/storage/cockroachkv/ordered_iterator.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "database/sql" + "errors" "fmt" "github.com/zeebo/errs" @@ -85,7 +86,7 @@ func (oci *orderedCockroachIterator) Next(ctx context.Context, item *storage.Lis defer mon.TaskNamed("acquire_new_query")(nil)(nil) retry := false - if err := oci.curRows.Err(); err != nil && err != sql.ErrNoRows { + if err := oci.curRows.Err(); err != nil && !errors.Is(err, sql.ErrNoRows) { // This NeedsRetry needs to be exported here because it is // expected behavior for cockroach to return retryable errors // that will be captured in this Rows object. diff --git a/storage/postgreskv/ordered_iterator.go b/storage/postgreskv/ordered_iterator.go index 8429a8e21..e6c1b3a68 100644 --- a/storage/postgreskv/ordered_iterator.go +++ b/storage/postgreskv/ordered_iterator.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "database/sql" + "errors" "fmt" "github.com/zeebo/errs" @@ -83,7 +84,7 @@ func (opi *orderedPostgresIterator) Next(ctx context.Context, item *storage.List result := func() bool { defer mon.TaskNamed("acquire_new_query")(nil)(nil) - if err := opi.curRows.Err(); err != nil && err != sql.ErrNoRows { + if err := opi.curRows.Err(); err != nil && !errors.Is(err, sql.ErrNoRows) { opi.errEncountered = errs.Wrap(err) return false } diff --git a/storagenode/gracefulexit/blobscleaner.go b/storagenode/gracefulexit/blobscleaner.go index 192e874ae..34cd480a2 100644 --- a/storagenode/gracefulexit/blobscleaner.go +++ b/storagenode/gracefulexit/blobscleaner.go @@ -6,6 +6,7 @@ package gracefulexit import ( "context" "database/sql" + "errors" "os" "go.uber.org/zap" @@ -45,7 +46,7 @@ func (blobsCleaner *BlobsCleaner) RemoveBlobs(ctx context.Context) (err error) { for i := 0; i < len(satelliteIDs); i++ { stats, err := blobsCleaner.satelliteDB.GetSatellite(ctx, satelliteIDs[i]) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { continue } diff --git a/storagenode/heldamount/service.go b/storagenode/heldamount/service.go index 77cd70f22..f05cac51c 100644 --- a/storagenode/heldamount/service.go +++ b/storagenode/heldamount/service.go @@ -6,6 +6,7 @@ package heldamount import ( "context" "database/sql" + "errors" "fmt" "strconv" "strings" @@ -259,7 +260,7 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string) satellite, err := service.satellitesDB.GetSatellite(ctx, satelliteIDs[i]) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { payoutHistory.IsExitComplete = false } diff --git a/storagenode/storagenodedb/heldamount.go b/storagenode/storagenodedb/heldamount.go index 55006ec83..93b227757 100644 --- a/storagenode/storagenodedb/heldamount.go +++ b/storagenode/storagenodedb/heldamount.go @@ -6,6 +6,7 @@ package storagenodedb import ( "context" "database/sql" + "errors" "github.com/zeebo/errs" @@ -137,7 +138,7 @@ func (db *heldamountDB) GetPayStub(ctx context.Context, satelliteID storj.NodeID &result.Paid, ) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { return nil, heldamount.ErrNoPayStubForPeriod.Wrap(err) } return nil, ErrHeldAmount.Wrap(err) @@ -150,7 +151,7 @@ func (db *heldamountDB) GetPayStub(ctx context.Context, satelliteID storj.NodeID err = rowPayment.Scan(&result.Receipt) if err != nil { - if sql.ErrNoRows == err { + if errors.Is(err, sql.ErrNoRows) { return &result, nil } return nil, ErrHeldAmount.Wrap(err)