all: replace == comparison with errors.Is
Change-Id: I05d9a369c7c6f144b94a4c524e8aea18eb9cb714
This commit is contained in:
parent
7b4a8c4d6d
commit
257855b5de
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
@ -73,7 +74,7 @@ func cmdDelete(cmd *cobra.Command, args []string) (err error) {
|
||||
segmentsSkipped := 0
|
||||
for {
|
||||
record, err := csvReader.Read()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@ -140,7 +141,7 @@ func wrapRows(rows driver.Rows) (crdbRows *cockroachRows, err error) {
|
||||
dest := make([]driver.Value, len(columns))
|
||||
err = rows.Next(dest)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return &cockroachRows{rows: rows, firstResults: nil, eof: true}, nil
|
||||
}
|
||||
return nil, err
|
||||
|
@ -6,6 +6,7 @@ package migrate
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -36,7 +37,7 @@ func Create(ctx context.Context, identifier string, db DBX) error {
|
||||
err = row.Scan(&previousSchema)
|
||||
|
||||
// not created yet
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
_, err := tx.ExecContext(ctx, schema)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -6,6 +6,7 @@ package migrate
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
@ -227,7 +228,7 @@ func (migration *Migration) getLatestVersion(ctx context.Context, log *zap.Logge
|
||||
/* #nosec G202 */ // Table name is white listed by the ValidTableName method
|
||||
// executed at the beginning of the function
|
||||
err := tx.QueryRow(ctx, rebind(db, `SELECT MAX(version) FROM `+migration.Table)).Scan(&version)
|
||||
if err == sql.ErrNoRows || !version.Valid {
|
||||
if errors.Is(err, sql.ErrNoRows) || !version.Valid {
|
||||
version.Int64 = -1
|
||||
return nil
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@ -1388,7 +1389,7 @@ func (s *Service) getProjectLimit(ctx context.Context, userID uuid.UUID) (limit
|
||||
|
||||
registrationToken, err := s.store.RegistrationTokens().GetByOwnerID(ctx, userID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return openRegistrationProjectLimit, nil
|
||||
}
|
||||
return 0, err
|
||||
|
@ -6,6 +6,7 @@ package orders
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"sort"
|
||||
"time"
|
||||
@ -241,7 +242,7 @@ func (endpoint *Endpoint) Settlement(stream pb.DRPCOrders_SettlementStream) (err
|
||||
}
|
||||
|
||||
formatError := func(err error) error {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return rpcstatus.Error(rpcstatus.Unknown, err.Error())
|
||||
@ -406,7 +407,7 @@ func (endpoint *Endpoint) SettlementWithWindow(stream pb.DRPCOrders_SettlementWi
|
||||
for {
|
||||
request, err = stream.Recv()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
log.Debug("err streaming order request", zap.Error(err))
|
||||
|
@ -93,7 +93,7 @@ func testCache(ctx context.Context, t *testing.T, store overlay.DB) {
|
||||
{ // Get
|
||||
_, err := service.Get(ctx, storj.NodeID{})
|
||||
require.Error(t, err)
|
||||
require.True(t, err == overlay.ErrEmptyNode)
|
||||
require.Equal(t, overlay.ErrEmptyNode, err)
|
||||
|
||||
valid1, err := service.Get(ctx, valid1ID)
|
||||
require.NoError(t, err)
|
||||
|
@ -5,6 +5,7 @@ package stripecoinpayments
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
@ -571,7 +572,7 @@ func (service *Service) createProjectRecords(ctx context.Context, customerID str
|
||||
}
|
||||
|
||||
if err = service.db.ProjectRecords().Check(ctx, project.ID, start, end); err != nil {
|
||||
if err == ErrProjectRecordExists {
|
||||
if errors.Is(err, ErrProjectRecordExists) {
|
||||
service.log.Warn("Record for this project already exists.", zap.String("Customer ID", customerID), zap.String("Project ID", project.ID.String()))
|
||||
continue
|
||||
}
|
||||
@ -678,7 +679,7 @@ func (service *Service) applyProjectRecords(ctx context.Context, records []Proje
|
||||
|
||||
cusID, err := service.db.Customers().GetCustomerID(ctx, proj.OwnerID)
|
||||
if err != nil {
|
||||
if err == ErrNoCustomer {
|
||||
if errors.Is(err, ErrNoCustomer) {
|
||||
service.log.Warn("Stripe customer does not exist for project owner.", zap.Stringer("Owner ID", proj.OwnerID), zap.Stringer("Project ID", proj.ID))
|
||||
continue
|
||||
}
|
||||
@ -808,7 +809,7 @@ func (service *Service) applyCoupons(ctx context.Context, usages []CouponUsage)
|
||||
|
||||
customerID, err := service.db.Customers().GetCustomerID(ctx, coupon.UserID)
|
||||
if err != nil {
|
||||
if err == ErrNoCustomer {
|
||||
if errors.Is(err, ErrNoCustomer) {
|
||||
service.log.Warn("Stripe customer does not exist for coupon owner.", zap.Stringer("User ID", coupon.UserID), zap.Stringer("Coupon ID", coupon.ID))
|
||||
continue
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package stripecoinpayments_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"math/big"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -167,7 +168,7 @@ func TestConcurrentConsume(t *testing.T) {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if err == stripecoinpayments.ErrTransactionConsumed {
|
||||
if errors.Is(err, stripecoinpayments.ErrTransactionConsumed) {
|
||||
appendError(err)
|
||||
return nil
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
@ -120,7 +121,7 @@ func (keys *attributionDB) Get(ctx context.Context, projectID uuid.UUID, bucketN
|
||||
dbx.ValueAttribution_ProjectId(projectID[:]),
|
||||
dbx.ValueAttribution_BucketName(bucketName),
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, attribution.ErrBucketNotAttributed.New("%q", bucketName)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -70,7 +70,7 @@ func (db *bucketsDB) GetBucket(ctx context.Context, bucketName []byte, projectID
|
||||
dbx.BucketMetainfo_Name(bucketName),
|
||||
)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return storj.Bucket{}, storj.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
@ -29,7 +30,7 @@ func (containment *containment) Get(ctx context.Context, id pb.NodeID) (_ *audit
|
||||
|
||||
pending, err := containment.db.Get_PendingAudits_By_NodeId(ctx, dbx.PendingAudits_NodeId(id.Bytes()))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, audit.ErrContainedNotFound.New("%v", id)
|
||||
}
|
||||
return nil, audit.ContainError.Wrap(err)
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@ -271,7 +272,7 @@ func (coupons *coupons) GetLatest(ctx context.Context, couponID uuid.UUID) (_ ti
|
||||
|
||||
var created time.Time
|
||||
err = amountRow.Scan(&created)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return created, stripecoinpayments.ErrNoCouponUsages.Wrap(err)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"storj.io/common/uuid"
|
||||
@ -42,7 +43,7 @@ func (customers *customers) GetCustomerID(ctx context.Context, userID uuid.UUID)
|
||||
|
||||
idRow, err := customers.db.Get_StripeCustomer_CustomerId_By_UserId(ctx, dbx.StripeCustomer_UserId(userID[:]))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", stripecoinpayments.ErrNoCustomer
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -48,7 +49,7 @@ func (db *gracefulexitDB) IncrementProgress(ctx context.Context, nodeID storj.No
|
||||
func (db *gracefulexitDB) GetProgress(ctx context.Context, nodeID storj.NodeID) (_ *gracefulexit.Progress, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
dbxProgress, err := db.db.Get_GracefulExitProgress_By_NodeId(ctx, dbx.GracefulExitProgress_NodeId(nodeID.Bytes()))
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, gracefulexit.ErrNodeNotFound.Wrap(err)
|
||||
|
||||
} else if err != nil {
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
@ -109,7 +110,7 @@ func (db *invoiceProjectRecords) Check(ctx context.Context, projectID uuid.UUID,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ func (db *invoiceProjectRecords) Get(ctx context.Context, projectID uuid.UUID, s
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"storj.io/common/pb"
|
||||
"storj.io/storj/satellite/satellitedb/dbx"
|
||||
@ -26,7 +27,7 @@ func (db *irreparableDB) IncrementRepairAttempts(ctx context.Context, segmentInf
|
||||
|
||||
dbxInfo, err := tx.Get_Irreparabledb_By_Segmentpath(ctx, dbx.Irreparabledb_Segmentpath(segmentInfo.Path))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
// no rows err, so create/insert an entry
|
||||
return tx.CreateNoReturn_Irreparabledb(
|
||||
ctx,
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@ -211,7 +212,7 @@ func (db *ordersDB) GetBucketBandwidth(ctx context.Context, projectID uuid.UUID,
|
||||
var sum *int64
|
||||
query := `SELECT SUM(settled) FROM bucket_bandwidth_rollups WHERE bucket_name = ? AND project_id = ? AND interval_start > ? AND interval_start <= ?`
|
||||
err = db.db.QueryRow(ctx, db.db.Rebind(query), bucketName, projectID[:], from.UTC(), to.UTC()).Scan(&sum)
|
||||
if err == sql.ErrNoRows || sum == nil {
|
||||
if errors.Is(err, sql.ErrNoRows) || sum == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return *sum, Error.Wrap(err)
|
||||
@ -224,7 +225,7 @@ func (db *ordersDB) GetStorageNodeBandwidth(ctx context.Context, nodeID storj.No
|
||||
var sum *int64
|
||||
query := `SELECT SUM(settled) FROM storagenode_bandwidth_rollups WHERE storagenode_id = ? AND interval_start > ? AND interval_start <= ?`
|
||||
err = db.db.QueryRow(ctx, db.db.Rebind(query), nodeID.Bytes(), from.UTC(), to.UTC()).Scan(&sum)
|
||||
if err == sql.ErrNoRows || sum == nil {
|
||||
if errors.Is(err, sql.ErrNoRows) || sum == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return *sum, err
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@ -136,7 +137,7 @@ func (cache *overlaycache) Get(ctx context.Context, id storj.NodeID) (_ *overlay
|
||||
}
|
||||
|
||||
node, err := cache.db.Get_Node_By_Id(ctx, dbx.Node_Id(id.Bytes()))
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, overlay.ErrNodeNotFound.New("%v", id)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
@ -31,7 +32,7 @@ func (idents *peerIdentities) Set(ctx context.Context, nodeID storj.NodeID, iden
|
||||
err = idents.db.WithTx(ctx, func(ctx context.Context, tx *dbx.Tx) (err error) {
|
||||
serial, err := tx.Get_PeerIdentity_LeafSerialNumber_By_NodeId(ctx, dbx.PeerIdentity_NodeId(nodeID.Bytes()))
|
||||
if serial == nil || err != nil {
|
||||
if serial == nil || err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) || serial == nil {
|
||||
return tx.CreateNoReturn_PeerIdentity(ctx,
|
||||
dbx.PeerIdentity_NodeId(nodeID.Bytes()),
|
||||
dbx.PeerIdentity_LeafSerialNumber(ident.Leaf.SerialNumber.Bytes()),
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@ -123,7 +124,7 @@ func (db *ProjectAccounting) GetAllocatedBandwidthTotal(ctx context.Context, pro
|
||||
var sum *int64
|
||||
query := `SELECT SUM(allocated) FROM bucket_bandwidth_rollups WHERE project_id = ? AND action = ? AND interval_start >= ?;`
|
||||
err = db.db.QueryRow(ctx, db.db.Rebind(query), projectID[:], pb.PieceAction_GET, from.UTC()).Scan(&sum)
|
||||
if err == sql.ErrNoRows || sum == nil {
|
||||
if errors.Is(err, sql.ErrNoRows) || sum == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@ -139,7 +140,7 @@ func (db *ProjectAccounting) GetProjectAllocatedBandwidth(ctx context.Context, p
|
||||
|
||||
query := `SELECT egress_allocated FROM project_bandwidth_rollups WHERE project_id = ? AND interval_month = ?;`
|
||||
err = db.db.QueryRow(ctx, db.db.Rebind(query), projectID[:], interval).Scan(&egress)
|
||||
if err == sql.ErrNoRows || egress == nil {
|
||||
if errors.Is(err, sql.ErrNoRows) || egress == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ package satellitedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -94,7 +95,7 @@ func (r *repairQueue) Select(ctx context.Context) (seg *pb.InjuredSegment, err e
|
||||
default:
|
||||
return seg, errs.New("invalid dbType: %v", r.db.implementation)
|
||||
}
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = storage.ErrEmptyQueue.New("")
|
||||
}
|
||||
return seg, err
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/spacemonkeygo/monkit/v3"
|
||||
@ -98,7 +99,7 @@ func (client *Client) Get(ctx context.Context, key storage.Key) (_ storage.Value
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, storage.ErrKeyNotFound.New("%q", key)
|
||||
}
|
||||
|
||||
@ -285,7 +286,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -305,7 +306,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return storage.ErrValueChanged.New("%q", key)
|
||||
}
|
||||
return Error.Wrap(err)
|
||||
@ -317,7 +318,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
|
||||
var metadata []byte
|
||||
err = row.Scan(&metadata)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
// Row not found for this fullpath.
|
||||
// Potentially because another concurrent transaction changed the row.
|
||||
return storage.ErrKeyNotFound.New("%q", key)
|
||||
|
@ -6,6 +6,7 @@ package filestore
|
||||
import (
|
||||
"context"
|
||||
"encoding/base32"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
@ -600,7 +601,7 @@ func (dir *Dir) listNamespacesInPath(ctx context.Context, path string) (ids [][]
|
||||
for {
|
||||
dirNames, err := openDir.Readdirnames(nameBatchSize)
|
||||
if err != nil {
|
||||
if err == io.EOF || os.IsNotExist(err) {
|
||||
if errors.Is(err, io.EOF) || os.IsNotExist(err) {
|
||||
return ids, nil
|
||||
}
|
||||
return ids, err
|
||||
@ -649,7 +650,7 @@ func (dir *Dir) walkNamespaceInPath(ctx context.Context, namespace []byte, path
|
||||
}
|
||||
subdirNames, err := openDir.Readdirnames(nameBatchSize)
|
||||
if err != nil {
|
||||
if err == io.EOF || os.IsNotExist(err) {
|
||||
if errors.Is(err, io.EOF) || os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
@ -763,7 +764,7 @@ func removeAllContent(ctx context.Context, path string) (err error) {
|
||||
// the file might be still in use, so ignore the error
|
||||
_ = os.RemoveAll(filepath.Join(path, file))
|
||||
}
|
||||
if err == io.EOF || len(files) == 0 {
|
||||
if errors.Is(err, io.EOF) || len(files) == 0 {
|
||||
return dir.Close()
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -6,6 +6,7 @@
|
||||
package filestore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -14,7 +15,7 @@ import (
|
||||
|
||||
func isBusy(err error) bool {
|
||||
err = underlyingError(err)
|
||||
return err == unix.EBUSY
|
||||
return errors.Is(err, unix.EBUSY)
|
||||
}
|
||||
|
||||
func diskInfoFromPath(path string) (info DiskInfo, err error) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
package filestore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -18,7 +19,7 @@ var errSharingViolation = windows.Errno(32)
|
||||
|
||||
func isBusy(err error) bool {
|
||||
err = underlyingError(err)
|
||||
return err == errSharingViolation
|
||||
return errors.Is(err, errSharingViolation)
|
||||
}
|
||||
|
||||
func diskInfoFromPath(path string) (info DiskInfo, err error) {
|
||||
@ -91,7 +92,7 @@ func getVolumeSerialNumber(path string) (string, error) {
|
||||
|
||||
// windows api occasionally returns
|
||||
func ignoreSuccess(err error) error {
|
||||
if err == windows.Errno(0) {
|
||||
if errors.Is(err, windows.Errno(0)) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -5,6 +5,7 @@ package filestore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -214,7 +215,7 @@ func (store *blobStore) TrashIsEmpty() (_ bool, err error) {
|
||||
}()
|
||||
|
||||
_, err = f.Readdirnames(1)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return true, nil
|
||||
}
|
||||
return false, err
|
||||
|
@ -6,6 +6,7 @@ package postgreskv
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/spacemonkeygo/monkit/v3"
|
||||
@ -94,7 +95,7 @@ func (client *Client) Get(ctx context.Context, key storage.Key) (_ storage.Value
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, storage.ErrKeyNotFound.New("%q", key)
|
||||
}
|
||||
|
||||
@ -243,7 +244,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -264,7 +265,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
|
||||
var val []byte
|
||||
err = row.Scan(&val)
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return storage.ErrValueChanged.New("%q", key)
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ package schema
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
@ -46,7 +47,7 @@ func PrepareDB(ctx context.Context, db tagsql.DB, dbURL string) error {
|
||||
return err
|
||||
}
|
||||
err = m.Up()
|
||||
if err == migrate.ErrNoChange {
|
||||
if errors.Is(err, migrate.ErrNoChange) {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
|
@ -6,6 +6,7 @@ package redis
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
@ -298,7 +299,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
}
|
||||
|
||||
err = client.db.Watch(txf, key.String())
|
||||
if err == redis.TxFailedErr {
|
||||
if errors.Is(err, redis.TxFailedErr) {
|
||||
return storage.ErrValueChanged.New("%q", key)
|
||||
}
|
||||
return Error.Wrap(err)
|
||||
@ -307,10 +308,10 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
||||
func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage.Value, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
value, err := cmdable.Get(string(key)).Bytes()
|
||||
if err == redis.Nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, storage.ErrKeyNotFound.New("%q", key)
|
||||
}
|
||||
if err != nil && err != redis.TxFailedErr {
|
||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||
return nil, Error.New("get error: %v", err)
|
||||
}
|
||||
return value, errs.Wrap(err)
|
||||
@ -319,7 +320,7 @@ func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage
|
||||
func put(ctx context.Context, cmdable redis.Cmdable, key storage.Key, value storage.Value, ttl time.Duration) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
err = cmdable.Set(key.String(), []byte(value), ttl).Err()
|
||||
if err != nil && err != redis.TxFailedErr {
|
||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||
return Error.New("put error: %v", err)
|
||||
}
|
||||
return errs.Wrap(err)
|
||||
@ -328,7 +329,7 @@ func put(ctx context.Context, cmdable redis.Cmdable, key storage.Key, value stor
|
||||
func delete(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
err = cmdable.Del(key.String()).Err()
|
||||
if err != nil && err != redis.TxFailedErr {
|
||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||
return Error.New("delete error: %v", err)
|
||||
}
|
||||
return errs.Wrap(err)
|
||||
@ -337,7 +338,7 @@ func delete(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (err er
|
||||
func eval(ctx context.Context, cmdable redis.Cmdable, script string, keys []string) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
err = cmdable.Eval(script, keys, nil).Err()
|
||||
if err != nil && err != redis.TxFailedErr {
|
||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||
return Error.New("eval error: %v", err)
|
||||
}
|
||||
return errs.Wrap(err)
|
||||
@ -350,7 +351,7 @@ func deleteMultiple(ctx context.Context, cmdable redis.Cmdable, keys []storage.K
|
||||
for _, key := range keys {
|
||||
value, err := get(ctx, cmdable, key)
|
||||
if err != nil {
|
||||
if errs.Is(err, redis.Nil) || storage.ErrKeyNotFound.Has(err) {
|
||||
if errors.Is(err, redis.Nil) || storage.ErrKeyNotFound.Has(err) {
|
||||
continue
|
||||
}
|
||||
return items, err
|
||||
@ -358,7 +359,7 @@ func deleteMultiple(ctx context.Context, cmdable redis.Cmdable, keys []storage.K
|
||||
|
||||
err = delete(ctx, cmdable, key)
|
||||
if err != nil {
|
||||
if errs.Is(err, redis.Nil) || storage.ErrKeyNotFound.Has(err) {
|
||||
if errors.Is(err, redis.Nil) || storage.ErrKeyNotFound.Has(err) {
|
||||
continue
|
||||
}
|
||||
return items, err
|
||||
|
@ -5,6 +5,7 @@ package orders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"math/rand"
|
||||
"time"
|
||||
@ -322,7 +323,7 @@ func (service *Service) settle(ctx context.Context, log *zap.Logger, satelliteID
|
||||
for {
|
||||
response, err := stream.Recv()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ package pieces
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"hash"
|
||||
"io"
|
||||
|
||||
@ -100,7 +101,7 @@ func (w *Writer) Write(data []byte) (int, error) {
|
||||
n, err := w.blob.Write(data)
|
||||
w.pieceSize += int64(n)
|
||||
_, _ = w.hash.Write(data[:n]) // guaranteed not to return an error
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return n, err
|
||||
}
|
||||
return n, Error.Wrap(err)
|
||||
@ -298,7 +299,7 @@ func (r *Reader) Read(data []byte) (int, error) {
|
||||
}
|
||||
n, err := r.blob.Read(data)
|
||||
r.pos += int64(n)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return n, err
|
||||
}
|
||||
return n, Error.Wrap(err)
|
||||
@ -323,7 +324,7 @@ func (r *Reader) Seek(offset int64, whence int) (int64, error) {
|
||||
pos -= V1PieceHeaderReservedArea
|
||||
}
|
||||
}
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return pos, err
|
||||
}
|
||||
return pos, Error.Wrap(err)
|
||||
@ -336,7 +337,7 @@ func (r *Reader) ReadAt(data []byte, offset int64) (int, error) {
|
||||
offset += V1PieceHeaderReservedArea
|
||||
}
|
||||
n, err := r.blob.ReadAt(data, offset)
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return n, err
|
||||
}
|
||||
return n, Error.Wrap(err)
|
||||
|
@ -4,6 +4,7 @@
|
||||
package pieces_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
@ -78,7 +79,7 @@ func BenchmarkReadWrite(b *testing.B) {
|
||||
for {
|
||||
_, err := reader.Read(data)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
require.NoError(b, err)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -103,7 +104,7 @@ func TestPieces(t *testing.T) {
|
||||
for {
|
||||
_, err := reader.Read(data)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
@ -6,6 +6,7 @@ package storagenodedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -148,7 +149,7 @@ func (db *bandwidthDB) getSummary(ctx context.Context, from, to time.Time, filte
|
||||
) GROUP BY action;
|
||||
`, from, to, from, to)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return usage, nil
|
||||
}
|
||||
return nil, ErrBandwidth.Wrap(err)
|
||||
@ -257,7 +258,7 @@ func (db *bandwidthDB) SummaryBySatellite(ctx context.Context, from, to time.Tim
|
||||
) GROUP BY satellite_id, action;
|
||||
`, from, to, from, to)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return entries, nil
|
||||
}
|
||||
return nil, ErrBandwidth.Wrap(err)
|
||||
|
@ -6,6 +6,7 @@ package storagenodedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
@ -69,7 +70,7 @@ func (db *ordersDB) ListUnsent(ctx context.Context, limit int) (_ []*orders.Info
|
||||
LIMIT ?
|
||||
`, limit)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, ErrOrders.Wrap(err)
|
||||
@ -128,7 +129,7 @@ func (db *ordersDB) ListUnsentBySatellite(ctx context.Context) (_ map[storj.Node
|
||||
FROM unsent_order
|
||||
`)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, ErrOrders.Wrap(err)
|
||||
@ -261,7 +262,7 @@ func (db *ordersDB) ListArchived(ctx context.Context, limit int) (_ []*orders.Ar
|
||||
LIMIT ?
|
||||
`, limit)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, ErrOrders.Wrap(err)
|
||||
@ -314,7 +315,7 @@ func (db *ordersDB) CleanArchive(ctx context.Context, ttl time.Duration) (_ int,
|
||||
WHERE archived_at <= ?
|
||||
`, deleteBefore)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, ErrOrders.Wrap(err)
|
||||
|
@ -6,6 +6,7 @@ package storagenodedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -44,7 +45,7 @@ func (db *pieceSpaceUsedDB) Init(ctx context.Context) (err error) {
|
||||
var piecesTotal int64
|
||||
err = totalPiecesRow.Scan(&piecesTotal)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = db.createInitTotalPieces(ctx)
|
||||
if err != nil {
|
||||
return ErrPieceSpaceUsed.Wrap(err)
|
||||
@ -61,7 +62,7 @@ func (db *pieceSpaceUsedDB) Init(ctx context.Context) (err error) {
|
||||
var trashTotal int64
|
||||
err = totalTrashRow.Scan(&trashTotal)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = db.createInitTotalTrash(ctx)
|
||||
if err != nil {
|
||||
return ErrPieceSpaceUsed.Wrap(err)
|
||||
@ -98,7 +99,7 @@ func (db *pieceSpaceUsedDB) GetPieceTotals(ctx context.Context) (total int64, co
|
||||
|
||||
err = row.Scan(&total, &contentSize)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
return 0, 0, ErrPieceSpaceUsed.Wrap(err)
|
||||
@ -118,7 +119,7 @@ func (db *pieceSpaceUsedDB) GetTrashTotal(ctx context.Context) (total int64, err
|
||||
|
||||
err = row.Scan(&total)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return total, nil
|
||||
}
|
||||
return total, ErrPieceSpaceUsed.Wrap(err)
|
||||
@ -137,7 +138,7 @@ func (db *pieceSpaceUsedDB) GetPieceTotalsForAllSatellites(ctx context.Context)
|
||||
AND satellite_id IS NOT ?
|
||||
`, trashTotalRowName)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, ErrPieceSpaceUsed.Wrap(err)
|
||||
@ -208,7 +209,7 @@ func (db *pieceSpaceUsedDB) UpdatePieceTotalsForAllSatellites(ctx context.Contex
|
||||
`, vals.Total, vals.ContentSize, satelliteID, vals.Total, vals.ContentSize, satelliteID)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
continue
|
||||
}
|
||||
return ErrPieceSpaceUsed.Wrap(err)
|
||||
|
@ -6,6 +6,7 @@ package storagenodedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -76,7 +77,7 @@ func (db *pricingDB) Get(ctx context.Context, satelliteID storj.NodeID) (_ *pric
|
||||
&pricingModel.DiskSpace,
|
||||
)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ package storagenodedb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
@ -133,7 +134,7 @@ func (db *reputationDB) Get(ctx context.Context, satelliteID storj.NodeID) (_ *r
|
||||
&stats.JoinedAt,
|
||||
)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ func (versions ProcessesConfig) ValidateRollouts(log *zap.Logger) error {
|
||||
continue
|
||||
}
|
||||
if err := binary.Rollout.Validate(); err != nil {
|
||||
if err == EmptySeedErr {
|
||||
if errors.Is(err, EmptySeedErr) {
|
||||
log.Warn(err.Error(), zap.String("binary", value.Type().Field(i).Name))
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user