Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify the error handling methods in the crypto package that are different from the project style #6439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/chainsync/slashfilter/mysqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slashfilter

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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
}

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

Expand Down
6 changes: 3 additions & 3 deletions pkg/ethhashlookup/eth_transaction_hash_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/httpreader/resumable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package httpreader

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/paychmgr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/paychmgr/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/state/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import (
"context"
"errors"

Check failure on line 5 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

other declaration of errors

Check failure on line 5 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

other declaration of errors
"fmt"
"strconv"

"github.com/filecoin-project/venus/venus-shared/types"
"github.com/pkg/errors"

Check failure on line 10 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

errors redeclared in this block

Check failure on line 10 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

"github.com/pkg/errors" imported and not used

Check failure on line 10 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

errors redeclared in this block

Check failure on line 10 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

"github.com/pkg/errors" imported and not used

"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/dline"
Expand Down Expand Up @@ -277,7 +278,7 @@
if err == nil {
return true, nil
}
if err == types.ErrActorNotFound {
if errors.Is(err, types.ErrActorNotFound) {
return false, nil
}
return false, err
Expand Down Expand Up @@ -512,7 +513,7 @@
func (v *View) StateMinerProvingDeadline(ctx context.Context, addr addr.Address, ts *types.TipSet) (*dline.Info, error) {
mas, err := v.LoadMinerState(ctx, addr)
if err != nil {
return nil, errors.WithMessage(err, "failed to get proving dealline")

Check failure on line 516 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

undefined: errors.WithMessage

Check failure on line 516 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

undefined: errors.WithMessage
}

height := ts.Height()
Expand Down Expand Up @@ -696,7 +697,7 @@
return addr.Undef, err
}
if !found {
return addr.Undef, errors.Wrapf(types.ErrActorNotFound, "address is :%s", address)

Check failure on line 700 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

undefined: errors.Wrapf

Check failure on line 700 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

undefined: errors.Wrapf
}

if tree.Version() >= vmstate.StateTreeVersion5 {
Expand Down Expand Up @@ -823,7 +824,7 @@
return nil, err
}
if !found {
return nil, errors.Wrapf(types.ErrActorNotFound, "address is :%s", address)

Check failure on line 827 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / test

undefined: errors.Wrapf

Check failure on line 827 in pkg/state/view.go

View workflow job for this annotation

GitHub Actions / check

undefined: errors.Wrapf
}

return actor, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/dag/oldpath/oldresolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading