all: fix error checking

Change-Id: Ia0da1bbd6ce695139922f94096c2419281905e32
This commit is contained in:
Egon Elbre 2020-07-16 18:50:15 +03:00
parent b84923558b
commit d8dcae3075
11 changed files with 25 additions and 17 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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)
}
}()

View File

@ -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.

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)