diff --git a/cmd/dispute.go b/cmd/dispute.go index 91e5f6c79a..ec1813dc3b 100644 --- a/cmd/dispute.go +++ b/cmd/dispute.go @@ -333,7 +333,7 @@ var disputerStartCmd = &cmds.Command{ for { err := disputeLoop() - if err == context.Canceled { + if errors.Is(err, context.Canceled) { disputeLog.Info("disputer shutting down") break } diff --git a/pkg/chainsync/slashfilter/mysqldb.go b/pkg/chainsync/slashfilter/mysqldb.go index 1754b756b5..69bbd242d3 100644 --- a/pkg/chainsync/slashfilter/mysqldb.go +++ b/pkg/chainsync/slashfilter/mysqldb.go @@ -2,6 +2,7 @@ package slashfilter import ( "context" + "errors" "fmt" "time" @@ -69,7 +70,7 @@ func NewMysqlSlashFilter(cfg config.MySQLConfig) (ISlashFilter, error) { func (f *MysqlSlashFilter) checkSameHeightFault(bh *types.BlockHeader) (cid.Cid, bool, error) { var bk MinedBlock err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and epoch=?", bh.Miner.String(), bh.Height).Error - if err == gorm.ErrRecordNotFound { + if errors.Is(err, gorm.ErrRecordNotFound) { return cid.Undef, false, nil } @@ -90,7 +91,7 @@ func (f *MysqlSlashFilter) checkSameHeightFault(bh *types.BlockHeader) (cid.Cid, func (f *MysqlSlashFilter) checkSameParentFault(bh *types.BlockHeader) (cid.Cid, bool, error) { var bk MinedBlock err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and parent_key=?", bh.Miner.String(), types.NewTipSetKey(bh.Parents...).String()).Error - if err == gorm.ErrRecordNotFound { + if errors.Is(err, gorm.ErrRecordNotFound) { return cid.Undef, false, nil } diff --git a/pkg/ethhashlookup/eth_transaction_hash_lookup.go b/pkg/ethhashlookup/eth_transaction_hash_lookup.go index 28d9451985..2bf0d8061b 100644 --- a/pkg/ethhashlookup/eth_transaction_hash_lookup.go +++ b/pkg/ethhashlookup/eth_transaction_hash_lookup.go @@ -72,7 +72,7 @@ func (ei *EthTxHashLookup) GetCidFromHash(txHash types.EthHash) (cid.Cid, error) var c string err := row.Scan(&c) if err != nil { - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return cid.Undef, ErrNotFound } return cid.Undef, err @@ -86,7 +86,7 @@ func (ei *EthTxHashLookup) GetHashFromCid(c cid.Cid) (types.EthHash, error) { var hashString string err := row.Scan(&c) if err != nil { - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return types.EmptyEthHash, ErrNotFound } return types.EmptyEthHash, err @@ -117,7 +117,7 @@ func NewTransactionHashLookup(path string) (*EthTxHashLookup, error) { } q, err := db.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='_meta';") - if err == sql.ErrNoRows || !q.Next() { + if errors.Is(err, sql.ErrNoRows) || !q.Next() { // empty database, create the schema for _, ddl := range ddls { if _, err := db.Exec(ddl); err != nil { diff --git a/pkg/httpreader/resumable.go b/pkg/httpreader/resumable.go index d940e2af7f..7fc8c33ac7 100644 --- a/pkg/httpreader/resumable.go +++ b/pkg/httpreader/resumable.go @@ -2,6 +2,7 @@ package httpreader import ( "context" + "errors" "fmt" "io" "net/http" @@ -103,7 +104,7 @@ func (r *ResumableReader) Read(p []byte) (n int, err error) { n, err = r.reader.Read(p) r.position += int64(n) - if err == io.EOF || err == io.ErrUnexpectedEOF { + if err == io.EOF || errors.Is(err, io.ErrUnexpectedEOF) { if r.position == r.contentLength { if err := r.reader.Close(); err != nil { log.Warnf("error closing reader: %+v", err) diff --git a/pkg/paychmgr/manager.go b/pkg/paychmgr/manager.go index 683830b728..dfeef88f2c 100644 --- a/pkg/paychmgr/manager.go +++ b/pkg/paychmgr/manager.go @@ -132,7 +132,7 @@ func (pm *Manager) AvailableFundsByFromTo(ctx context.Context, from address.Addr } ci, err := ca.outboundActiveByFromTo(ctx, from, to) - if err == ErrChannelNotTracked { + if errors.Is(err, ErrChannelNotTracked) { // If there is no active channel between from / to we still want to // return an empty ChannelAvailableFunds, so that clients can check // for the existence of a channel between from / to without getting @@ -167,7 +167,7 @@ func (pm *Manager) GetPaychWaitReady(ctx context.Context, mcid cid.Cid) (address pm.lk.Unlock() if err != nil { - if err == datastore.ErrNotFound { + if errors.Is(err, datastore.ErrNotFound) { return address.Undef, fmt.Errorf("could not find wait msg cid %s", mcid) } return address.Undef, err diff --git a/pkg/paychmgr/store.go b/pkg/paychmgr/store.go index 6f48ab33df..97ac6d03e2 100644 --- a/pkg/paychmgr/store.go +++ b/pkg/paychmgr/store.go @@ -291,7 +291,7 @@ func (ps *Store) ByChannelID(ctx context.Context, channelID string) (*pchTypes.C res, err := ps.ds.Get(ctx, dskeyForChannel(channelID)) if err != nil { - if err == datastore.ErrNotFound { + if errors.Is(err, datastore.ErrNotFound) { return nil, ErrChannelNotTracked } return nil, err diff --git a/pkg/state/view.go b/pkg/state/view.go index 396630b077..043cc0dc06 100644 --- a/pkg/state/view.go +++ b/pkg/state/view.go @@ -2,6 +2,7 @@ package state import ( "context" + "errors" "fmt" "strconv" @@ -277,7 +278,7 @@ func (v *View) MinerExists(ctx context.Context, maddr addr.Address) (bool, error if err == nil { return true, nil } - if err == types.ErrActorNotFound { + if errors.Is(err, types.ErrActorNotFound) { return false, nil } return false, err diff --git a/pkg/util/dag/oldpath/oldresolver/resolver.go b/pkg/util/dag/oldpath/oldresolver/resolver.go index eb3f81cbaf..3d436df3bf 100644 --- a/pkg/util/dag/oldpath/oldresolver/resolver.go +++ b/pkg/util/dag/oldpath/oldresolver/resolver.go @@ -83,7 +83,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid. } if err != nil { - if err == dag.ErrLinkNotFound { + if errors.Is(err, dag.ErrLinkNotFound) { err = ErrNoLink{Name: p[0], Node: nd.Cid()} } return cid.Cid{}, nil, err @@ -104,7 +104,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid. // Confirm the path exists within the object val, rest, err := nd.Resolve(p) if err != nil { - if err == dag.ErrLinkNotFound { + if errors.Is(err, dag.ErrLinkNotFound) { err = ErrNoLink{Name: p[0], Node: nd.Cid()} } return cid.Cid{}, nil, err @@ -179,7 +179,7 @@ func (r *Resolver) ResolveLinks(ctx context.Context, ndd ipld.Node, names []stri defer cancel() lnk, rest, err := r.ResolveOnce(ctx, r.DAG, nd, names) - if err == dag.ErrLinkNotFound { + if errors.Is(err, dag.ErrLinkNotFound) { return result, ErrNoLink{Name: names[0], Node: nd.Cid()} } else if err != nil { return result, err