Swtich to xerrors

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-11-22 10:20:56 -06:00
parent 6b36f19a9d
commit 36b7c5a32a
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
17 changed files with 54 additions and 47 deletions

View File

@ -2,10 +2,11 @@ package build
import (
"context"
"github.com/filecoin-project/lotus/lib/addrutil"
"os"
"strings"
"github.com/filecoin-project/lotus/lib/addrutil"
rice "github.com/GeertJohan/go.rice"
"github.com/libp2p/go-libp2p-core/peer"
)

View File

@ -2,9 +2,9 @@ package address
import (
"encoding/base32"
"errors"
"github.com/minio/blake2b-simd"
errors "github.com/pkg/errors"
)
func init() {

View File

@ -24,7 +24,6 @@ import (
hamt "github.com/ipfs/go-hamt-ipld"
bstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log"
"github.com/pkg/errors"
cbg "github.com/whyrusleeping/cbor-gen"
pubsub "github.com/whyrusleeping/pubsub"
"golang.org/x/xerrors"
@ -100,12 +99,12 @@ func (cs *ChainStore) Load() error {
return nil
}
if err != nil {
return errors.Wrap(err, "failed to load chain state from datastore")
return xerrors.Errorf("failed to load chain state from datastore: %w", err)
}
var tscids []cid.Cid
if err := json.Unmarshal(head, &tscids); err != nil {
return errors.Wrap(err, "failed to unmarshal stored chain head")
return xerrors.Errorf("failed to unmarshal stored chain head: %w", err)
}
ts, err := cs.LoadTipSet(tscids)
@ -121,11 +120,11 @@ func (cs *ChainStore) Load() error {
func (cs *ChainStore) writeHead(ts *types.TipSet) error {
data, err := json.Marshal(ts.Cids())
if err != nil {
return errors.Wrap(err, "failed to marshal tipset")
return xerrors.Errorf("failed to marshal tipset: %w", err)
}
if err := cs.ds.Put(chainHeadKey, data); err != nil {
return errors.Wrap(err, "failed to write chain head to datastore")
return xerrors.Errorf("failed to write chain head to datastore: %w", err)
}
return nil
@ -209,7 +208,7 @@ func (cs *ChainStore) PutTipSet(ctx context.Context, ts *types.TipSet) error {
log.Debugf("expanded %s into %s\n", ts.Cids(), expanded.Cids())
if err := cs.MaybeTakeHeavierTipSet(ctx, expanded); err != nil {
return errors.Wrap(err, "MaybeTakeHeavierTipSet failed in PutTipSet")
return xerrors.Errorf("MaybeTakeHeavierTipSet failed in PutTipSet: %w", err)
}
return nil
}
@ -507,7 +506,7 @@ func (cs *ChainStore) AddBlock(ctx context.Context, b *types.BlockHeader) error
}
if err := cs.MaybeTakeHeavierTipSet(ctx, ts); err != nil {
return errors.Wrap(err, "MaybeTakeHeavierTipSet failed")
return xerrors.Errorf("MaybeTakeHeavierTipSet failed: %w", err)
}
return nil
@ -667,12 +666,12 @@ func (cs *ChainStore) readMsgMetaCids(mmc cid.Cid) ([]cid.Cid, []cid.Cid, error)
blscids, err := cs.readAMTCids(msgmeta.BlsMessages)
if err != nil {
return nil, nil, errors.Wrap(err, "loading bls message cids for block")
return nil, nil, xerrors.Errorf("loading bls message cids for block: %w", err)
}
secpkcids, err := cs.readAMTCids(msgmeta.SecpkMessages)
if err != nil {
return nil, nil, errors.Wrap(err, "loading secpk message cids for block")
return nil, nil, xerrors.Errorf("loading secpk message cids for block: %w", err)
}
cs.mmCache.Add(mmc, &mmCids{
@ -691,12 +690,12 @@ func (cs *ChainStore) MessagesForBlock(b *types.BlockHeader) ([]*types.Message,
blsmsgs, err := cs.LoadMessagesFromCids(blscids)
if err != nil {
return nil, nil, errors.Wrap(err, "loading bls messages for block")
return nil, nil, xerrors.Errorf("loading bls messages for block: %w", err)
}
secpkmsgs, err := cs.LoadSignedMessagesFromCids(secpkcids)
if err != nil {
return nil, nil, errors.Wrap(err, "loading secpk messages for block")
return nil, nil, xerrors.Errorf("loading secpk messages for block: %w", err)
}
return blsmsgs, secpkmsgs, nil
@ -706,7 +705,7 @@ func (cs *ChainStore) GetParentReceipt(b *types.BlockHeader, i int) (*types.Mess
bs := amt.WrapBlockstore(cs.bs)
a, err := amt.LoadAMT(bs, b.ParentMessageReceipts)
if err != nil {
return nil, errors.Wrap(err, "amt load")
return nil, xerrors.Errorf("amt load: %w", err)
}
var r types.MessageReceipt
@ -722,7 +721,7 @@ func (cs *ChainStore) LoadMessagesFromCids(cids []cid.Cid) ([]*types.Message, er
for i, c := range cids {
m, err := cs.GetMessage(c)
if err != nil {
return nil, errors.Wrapf(err, "failed to get message: (%s):%d", c, i)
return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", err, c, i)
}
msgs = append(msgs, m)
@ -736,7 +735,7 @@ func (cs *ChainStore) LoadSignedMessagesFromCids(cids []cid.Cid) ([]*types.Signe
for i, c := range cids {
m, err := cs.GetSignedMessage(c)
if err != nil {
return nil, errors.Wrapf(err, "failed to get message: (%s):%d", c, i)
return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", err, c, i)
}
msgs = append(msgs, m)

View File

@ -2,12 +2,13 @@ package store
import (
"context"
"math/big"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"golang.org/x/xerrors"
"math/big"
)
var zero = types.NewInt(0)

View File

@ -2,8 +2,7 @@ package validation
import (
"context"
"github.com/pkg/errors"
"errors"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/address"

View File

@ -2,14 +2,14 @@ package validation
import (
"context"
"errors"
"fmt"
"math/rand"
"github.com/pkg/errors"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/vm"
"golang.org/x/xerrors"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
@ -109,7 +109,7 @@ func (s *StateWrapper) SetActor(addr vstate.Address, code vstate.ActorCodeID, ba
// The ID-based address is dropped here, but should be reported back to the caller.
_, err = tree.RegisterNewAddress(addrInt, &actr.Actor)
if err != nil {
return nil, nil, errors.Wrapf(err, "register new address for actor")
return nil, nil, xerrors.Errorf("register new address for actor: %w", err)
}
return actr, s.storage, s.flush(tree)
}
@ -131,7 +131,7 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
return nil, nil, err
}
if err := tree.SetActor(actors.InitAddress, initact); err != nil {
return nil, nil, errors.Wrapf(err, "set init actor")
return nil, nil, xerrors.Errorf("set init actor: %w", err)
}
return &actorWrapper{*initact}, s.storage, s.flush(tree)
@ -141,7 +141,7 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
return nil, nil, err
}
if err := tree.SetActor(actors.StorageMarketAddress, smact); err != nil {
return nil, nil, errors.Wrapf(err, "set network storage market actor")
return nil, nil, xerrors.Errorf("set network storage market actor: %w", err)
}
return &actorWrapper{*smact}, s.storage, s.flush(tree)
case actors.StoragePowerAddress:
@ -150,7 +150,7 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
return nil, nil, err
}
if err := tree.SetActor(actors.StoragePowerAddress, spact); err != nil {
return nil, nil, errors.Wrapf(err, "set network storage market actor")
return nil, nil, xerrors.Errorf("set network storage market actor: %w", err)
}
return &actorWrapper{*spact}, s.storage, s.flush(tree)
case actors.NetworkAddress:
@ -160,7 +160,7 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
Head: vm.EmptyObjectCid,
}
if err := tree.SetActor(actors.NetworkAddress, ntwkact); err != nil {
return nil, nil, errors.Wrapf(err, "set network actor")
return nil, nil, xerrors.Errorf("set network actor: %w", err)
}
return &actorWrapper{*ntwkact}, s.storage, s.flush(tree)
case actors.BurntFundsAddress:
@ -170,7 +170,7 @@ func (s *StateWrapper) SetSingletonActor(addr vstate.SingletonActorID, balance v
Head: vm.EmptyObjectCid,
}
if err := tree.SetActor(actors.BurntFundsAddress, ntwkact); err != nil {
return nil, nil, errors.Wrapf(err, "set network actor")
return nil, nil, xerrors.Errorf("set network actor: %w", err)
}
return &actorWrapper{*ntwkact}, s.storage, s.flush(tree)
default:

View File

@ -4,9 +4,10 @@ import (
"bytes"
"container/list"
"context"
"sync"
actors2 "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/address"
"sync"
"github.com/ipfs/go-cid"

2
go.mod
View File

@ -103,7 +103,7 @@ require (
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
google.golang.org/api v0.9.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8

2
go.sum
View File

@ -689,6 +689,8 @@ golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBn
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/api v0.3.2/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=

View File

@ -1,8 +1,9 @@
package padreader
import (
"gotest.tools/assert"
"testing"
"gotest.tools/assert"
)
func TestComputePaddedSize(t *testing.T) {

View File

@ -2,14 +2,15 @@ package main
import (
"crypto/rand"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/node/repo"
"io"
"io/ioutil"
"os"
"sync"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/node/repo"
)
type NodeState int

View File

@ -3,12 +3,13 @@ package main
import (
"bufio"
"fmt"
"github.com/gorilla/websocket"
"github.com/opentracing/opentracing-go/log"
"io"
"net/http"
"strings"
"sync"
"github.com/gorilla/websocket"
"github.com/opentracing/opentracing-go/log"
)
type outmux struct {

View File

@ -13,7 +13,6 @@ import (
"github.com/filecoin-project/lotus/node/impl/full"
logging "github.com/ipfs/go-log"
"github.com/pkg/errors"
"go.opencensus.io/trace"
"go.uber.org/fx"
"golang.org/x/xerrors"
@ -250,12 +249,12 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
log.Debugw("attempting to mine a block", "tipset", types.LogCids(base.ts.Cids()))
ticket, err := m.scratchTicket(ctx, addr, base)
if err != nil {
return nil, errors.Wrap(err, "scratching ticket failed")
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
}
win, proof, err := gen.IsRoundWinner(ctx, base.ts, append(base.tickets, ticket), addr, &m.api)
if err != nil {
return nil, errors.Wrap(err, "failed to check if we win next round")
return nil, xerrors.Errorf("failed to check if we win next round: %w", err)
}
if !win {
@ -265,7 +264,7 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
b, err := m.createBlock(base, addr, ticket, proof)
if err != nil {
return nil, errors.Wrap(err, "failed to create block")
return nil, xerrors.Errorf("failed to create block: %w", err)
}
log.Infow("mined new block", "cid", b.Cid())
@ -330,7 +329,7 @@ func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *type
pending, err := m.api.MpoolPending(context.TODO(), base.ts)
if err != nil {
return nil, errors.Wrapf(err, "failed to get pending messages")
return nil, xerrors.Errorf("failed to get pending messages: %w", err)
}
msgs, err := selectMessages(context.TODO(), m.api.StateGetActor, base, pending)

View File

@ -3,6 +3,9 @@ package modules
import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
@ -14,8 +17,6 @@ import (
"github.com/libp2p/go-libp2p-core/peerstore"
record "github.com/libp2p/go-libp2p-record"
"golang.org/x/xerrors"
"io"
"io/ioutil"
)
var log = logging.Logger("modules")

View File

@ -2,6 +2,7 @@ package storage
import (
"context"
"errors"
"sync"
"github.com/ipfs/go-cid"
@ -9,7 +10,7 @@ import (
"github.com/ipfs/go-datastore/namespace"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/host"
"github.com/pkg/errors"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/address"
@ -92,7 +93,7 @@ func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datasto
func (m *Miner) Run(ctx context.Context) error {
if err := m.runPreflightChecks(ctx); err != nil {
return errors.Wrap(err, "miner preflight checks failed")
return xerrors.Errorf("miner preflight checks failed: %w", err)
}
m.events = events.NewEvents(ctx, m.api)
@ -122,7 +123,7 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error {
has, err := m.api.WalletHas(ctx, worker)
if err != nil {
return errors.Wrap(err, "failed to check wallet for worker key")
return xerrors.Errorf("failed to check wallet for worker key: %w", err)
}
if !has {

View File

@ -3,7 +3,6 @@ package storage
import (
"context"
"github.com/pkg/errors"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api"
@ -206,7 +205,7 @@ func (m *Miner) committing(ctx context.Context, sector SectorInfo) (func(*Sector
smsg, err := m.api.MpoolPushMessage(ctx, msg)
if err != nil {
log.Error(errors.Wrap(err, "pushing message to mpool"))
log.Error(xerrors.Errorf("pushing message to mpool: %w", err))
}
// TODO: Separate state before this wait, so we persist message cid?

View File

@ -2,7 +2,8 @@ package sectorblocks
import (
"context"
"github.com/ipfs/go-block-format"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
)