diff --git a/cmd/segment-reaper/delete.go b/cmd/segment-reaper/delete.go index fd35e3509..4fe2d5519 100644 --- a/cmd/segment-reaper/delete.go +++ b/cmd/segment-reaper/delete.go @@ -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 { diff --git a/private/dbutil/cockroachutil/driver.go b/private/dbutil/cockroachutil/driver.go index 6657b06b5..25a4e1207 100644 --- a/private/dbutil/cockroachutil/driver.go +++ b/private/dbutil/cockroachutil/driver.go @@ -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 diff --git a/private/migrate/create.go b/private/migrate/create.go index f0aa3cfe7..fe7ce5918 100644 --- a/private/migrate/create.go +++ b/private/migrate/create.go @@ -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 diff --git a/private/migrate/versions.go b/private/migrate/versions.go index 940d8b1e1..7ab98af13 100644 --- a/private/migrate/versions.go +++ b/private/migrate/versions.go @@ -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 } diff --git a/satellite/console/service.go b/satellite/console/service.go index 507893c71..1ca857abc 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" @@ -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 diff --git a/satellite/orders/endpoint.go b/satellite/orders/endpoint.go index 4dde08edc..06f3cd581 100644 --- a/satellite/orders/endpoint.go +++ b/satellite/orders/endpoint.go @@ -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)) diff --git a/satellite/overlay/service_test.go b/satellite/overlay/service_test.go index 0d2ccd694..00dd103a2 100644 --- a/satellite/overlay/service_test.go +++ b/satellite/overlay/service_test.go @@ -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) diff --git a/satellite/payments/stripecoinpayments/service.go b/satellite/payments/stripecoinpayments/service.go index 8569a3f86..dcd4e7c94 100644 --- a/satellite/payments/stripecoinpayments/service.go +++ b/satellite/payments/stripecoinpayments/service.go @@ -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 } diff --git a/satellite/payments/stripecoinpayments/transactions_test.go b/satellite/payments/stripecoinpayments/transactions_test.go index d150faa8b..d041f0501 100644 --- a/satellite/payments/stripecoinpayments/transactions_test.go +++ b/satellite/payments/stripecoinpayments/transactions_test.go @@ -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 } diff --git a/satellite/satellitedb/attribution.go b/satellite/satellitedb/attribution.go index 7c39d24a8..2ca4a2dbe 100644 --- a/satellite/satellitedb/attribution.go +++ b/satellite/satellitedb/attribution.go @@ -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 { diff --git a/satellite/satellitedb/buckets.go b/satellite/satellitedb/buckets.go index 8c1a72479..245bf07a8 100644 --- a/satellite/satellitedb/buckets.go +++ b/satellite/satellitedb/buckets.go @@ -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) diff --git a/satellite/satellitedb/containment.go b/satellite/satellitedb/containment.go index c35e74709..d2384c2a5 100644 --- a/satellite/satellitedb/containment.go +++ b/satellite/satellitedb/containment.go @@ -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) diff --git a/satellite/satellitedb/coupons.go b/satellite/satellitedb/coupons.go index 9911ec035..cc62c4f03 100644 --- a/satellite/satellitedb/coupons.go +++ b/satellite/satellitedb/coupons.go @@ -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) } diff --git a/satellite/satellitedb/customers.go b/satellite/satellitedb/customers.go index 9e03f32fa..f7ef01515 100644 --- a/satellite/satellitedb/customers.go +++ b/satellite/satellitedb/customers.go @@ -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 } diff --git a/satellite/satellitedb/gracefulexit.go b/satellite/satellitedb/gracefulexit.go index 6d9ea2708..89ea0d4f3 100644 --- a/satellite/satellitedb/gracefulexit.go +++ b/satellite/satellitedb/gracefulexit.go @@ -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 { diff --git a/satellite/satellitedb/invoiceprojectrecords.go b/satellite/satellitedb/invoiceprojectrecords.go index 888a5370e..ae9f56834 100644 --- a/satellite/satellitedb/invoiceprojectrecords.go +++ b/satellite/satellitedb/invoiceprojectrecords.go @@ -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 diff --git a/satellite/satellitedb/irreparabledb.go b/satellite/satellitedb/irreparabledb.go index 46cd2bfaa..2332e9cdd 100644 --- a/satellite/satellitedb/irreparabledb.go +++ b/satellite/satellitedb/irreparabledb.go @@ -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, diff --git a/satellite/satellitedb/orders.go b/satellite/satellitedb/orders.go index e65b7efce..2aae2f75c 100644 --- a/satellite/satellitedb/orders.go +++ b/satellite/satellitedb/orders.go @@ -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 diff --git a/satellite/satellitedb/overlaycache.go b/satellite/satellitedb/overlaycache.go index 479d32a98..ee5b4a8c2 100644 --- a/satellite/satellitedb/overlaycache.go +++ b/satellite/satellitedb/overlaycache.go @@ -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 { diff --git a/satellite/satellitedb/peeridentities.go b/satellite/satellitedb/peeridentities.go index a5c51c59e..b4f21684a 100644 --- a/satellite/satellitedb/peeridentities.go +++ b/satellite/satellitedb/peeridentities.go @@ -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()), diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index b9f571490..a1c4e5906 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -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 } diff --git a/satellite/satellitedb/repairqueue.go b/satellite/satellitedb/repairqueue.go index 1ebfdec3b..7d53cbcb4 100644 --- a/satellite/satellitedb/repairqueue.go +++ b/satellite/satellitedb/repairqueue.go @@ -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 diff --git a/storage/cockroachkv/client.go b/storage/cockroachkv/client.go index 6f8ed070a..1e031c6f4 100644 --- a/storage/cockroachkv/client.go +++ b/storage/cockroachkv/client.go @@ -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) diff --git a/storage/filestore/dir.go b/storage/filestore/dir.go index 0332fd337..290a9e006 100644 --- a/storage/filestore/dir.go +++ b/storage/filestore/dir.go @@ -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 { diff --git a/storage/filestore/dir_unix.go b/storage/filestore/dir_unix.go index 18747415a..6cef177c5 100644 --- a/storage/filestore/dir_unix.go +++ b/storage/filestore/dir_unix.go @@ -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) { diff --git a/storage/filestore/dir_windows.go b/storage/filestore/dir_windows.go index 234db5a65..66ea0e6a3 100644 --- a/storage/filestore/dir_windows.go +++ b/storage/filestore/dir_windows.go @@ -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 diff --git a/storage/filestore/store.go b/storage/filestore/store.go index fcf8e7980..720190b9f 100644 --- a/storage/filestore/store.go +++ b/storage/filestore/store.go @@ -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 diff --git a/storage/postgreskv/client.go b/storage/postgreskv/client.go index d9f275ca3..0cc74908a 100644 --- a/storage/postgreskv/client.go +++ b/storage/postgreskv/client.go @@ -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) } diff --git a/storage/postgreskv/schema/migrate.go b/storage/postgreskv/schema/migrate.go index 71f36d6d5..a8529d26a 100644 --- a/storage/postgreskv/schema/migrate.go +++ b/storage/postgreskv/schema/migrate.go @@ -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 diff --git a/storage/redis/client.go b/storage/redis/client.go index 224e29ae0..a4d1ae500 100644 --- a/storage/redis/client.go +++ b/storage/redis/client.go @@ -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 diff --git a/storagenode/orders/service.go b/storagenode/orders/service.go index 713d0a189..4e8765ab2 100644 --- a/storagenode/orders/service.go +++ b/storagenode/orders/service.go @@ -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 } diff --git a/storagenode/pieces/readwrite.go b/storagenode/pieces/readwrite.go index ea354a689..44d43a96e 100644 --- a/storagenode/pieces/readwrite.go +++ b/storagenode/pieces/readwrite.go @@ -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) diff --git a/storagenode/pieces/readwrite_test.go b/storagenode/pieces/readwrite_test.go index 53b3a9529..daf25c8b5 100644 --- a/storagenode/pieces/readwrite_test.go +++ b/storagenode/pieces/readwrite_test.go @@ -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) diff --git a/storagenode/pieces/store_test.go b/storagenode/pieces/store_test.go index fa7ee489a..d3a670a86 100644 --- a/storagenode/pieces/store_test.go +++ b/storagenode/pieces/store_test.go @@ -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) diff --git a/storagenode/storagenodedb/bandwidthdb.go b/storagenode/storagenodedb/bandwidthdb.go index 8e6f05815..c4ee49dba 100644 --- a/storagenode/storagenodedb/bandwidthdb.go +++ b/storagenode/storagenodedb/bandwidthdb.go @@ -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) diff --git a/storagenode/storagenodedb/orders.go b/storagenode/storagenodedb/orders.go index ad6e25872..417ffb456 100644 --- a/storagenode/storagenodedb/orders.go +++ b/storagenode/storagenodedb/orders.go @@ -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) diff --git a/storagenode/storagenodedb/piecespaceused.go b/storagenode/storagenodedb/piecespaceused.go index 1814c2db4..337ac150f 100644 --- a/storagenode/storagenodedb/piecespaceused.go +++ b/storagenode/storagenodedb/piecespaceused.go @@ -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) diff --git a/storagenode/storagenodedb/pricing.go b/storagenode/storagenodedb/pricing.go index 1f70cb86b..5ec2806da 100644 --- a/storagenode/storagenodedb/pricing.go +++ b/storagenode/storagenodedb/pricing.go @@ -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 } diff --git a/storagenode/storagenodedb/reputation.go b/storagenode/storagenodedb/reputation.go index 7a3908e16..6055fc2c7 100644 --- a/storagenode/storagenodedb/reputation.go +++ b/storagenode/storagenodedb/reputation.go @@ -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 } diff --git a/versioncontrol/peer.go b/versioncontrol/peer.go index 447e8cfaf..86a25ae14 100644 --- a/versioncontrol/peer.go +++ b/versioncontrol/peer.go @@ -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 }