Skip to content

Commit

Permalink
chore: use fmt.Errorf replace to xerrors.Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
ta0li committed Sep 29, 2022
1 parent 01b8dc4 commit bfbc6d4
Show file tree
Hide file tree
Showing 87 changed files with 353 additions and 310 deletions.
1 change: 1 addition & 0 deletions venus-devtool/compatible/actors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ var replicaCmd = &cli.Command{
{"\"github.com/filecoin-project/lotus/node/modules/dtypes\"", ""},
{"\"github.com/filecoin-project/lotus/chain/types\"", "types \"github.com/filecoin-project/venus/venus-shared/internal\""},
{"\"github.com/filecoin-project/lotus/blockstore\"", "blockstore \"github.com/filecoin-project/venus/pkg/util/blockstoreutil\""},
{"golang.org/x/xerrors", "fmt"},
}

for _, file := range files {
Expand Down
2 changes: 2 additions & 0 deletions venus-devtool/compatible/actors/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var replacers = [][2]string{
"dtypes.NetworkName",
"string",
},
{"\"golang.org/x/xerrors\"", "\"fmt\""},
{"xerrors.Errorf", "fmt.Errorf"},
}

func findActorsPkgDir() (string, error) {
Expand Down
9 changes: 5 additions & 4 deletions venus-shared/actors/builtin/account/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package account

import (
"fmt"

actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/cbor"
Expand Down Expand Up @@ -35,7 +36,7 @@ var Methods = builtin9.MethodsAccount
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.AccountKey {
return nil, xerrors.Errorf("actor code is not account: %s", name)
return nil, fmt.Errorf("actor code is not account: %s", name)
}

switch av {
Expand Down Expand Up @@ -74,7 +75,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {

}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version, addr address.Address) (State, error) {
Expand Down Expand Up @@ -108,7 +109,7 @@ func MakeState(store adt.Store, av actorstypes.Version, addr address.Address) (S
return make9(store, addr)

}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

type State interface {
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/actors/builtin/account/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package account
import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"golang.org/x/xerrors"
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/cbor"
Expand All @@ -26,7 +26,7 @@ var Methods = builtin{{.latestVersion}}.MethodsAccount
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.AccountKey {
return nil, xerrors.Errorf("actor code is not account: %s", name)
return nil, fmt.Errorf("actor code is not account: %s", name)
}

switch av {
Expand All @@ -48,7 +48,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
{{end}}
}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version, addr address.Address) (State, error) {
Expand All @@ -58,7 +58,7 @@ func MakeState(store adt.Store, av actorstypes.Version, addr address.Address) (S
return make{{.}}(store, addr)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

type State interface {
Expand Down
9 changes: 5 additions & 4 deletions venus-shared/actors/builtin/cron/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package cron

import (
"fmt"

actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/actors/adt"
types "github.com/filecoin-project/venus/venus-shared/internal"
"golang.org/x/xerrors"

builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"

Expand All @@ -29,7 +30,7 @@ import (
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.CronKey {
return nil, xerrors.Errorf("actor code is not cron: %s", name)
return nil, fmt.Errorf("actor code is not cron: %s", name)
}

switch av {
Expand Down Expand Up @@ -68,7 +69,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {

}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version) (State, error) {
Expand Down Expand Up @@ -102,7 +103,7 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) {
return make9(store)

}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

var (
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/actors/builtin/cron/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/actors/adt"
"golang.org/x/xerrors"
"fmt"
types "github.com/filecoin-project/venus/venus-shared/internal"

{{range .versions}}
Expand All @@ -20,7 +20,7 @@ import (
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.CronKey {
return nil, xerrors.Errorf("actor code is not cron: %s", name)
return nil, fmt.Errorf("actor code is not cron: %s", name)
}

switch av {
Expand All @@ -42,7 +42,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
{{end}}
}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version) (State, error) {
Expand All @@ -52,7 +52,7 @@ func MakeState(store adt.Store, av actorstypes.Version) (State, error) {
return make{{.}}(store)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

var (
Expand Down
9 changes: 5 additions & 4 deletions venus-shared/actors/builtin/init/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package init

import (
"fmt"

actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -40,7 +41,7 @@ var (
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.InitKey {
return nil, xerrors.Errorf("actor code is not init: %s", name)
return nil, fmt.Errorf("actor code is not init: %s", name)
}

switch av {
Expand Down Expand Up @@ -79,7 +80,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {

}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version, networkName string) (State, error) {
Expand Down Expand Up @@ -113,7 +114,7 @@ func MakeState(store adt.Store, av actorstypes.Version, networkName string) (Sta
return make9(store, networkName)

}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

type State interface {
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/actors/builtin/init/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package init
import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/venus/venus-shared/actors"
"golang.org/x/xerrors"
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
Expand All @@ -31,7 +31,7 @@ var (
func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != actors.InitKey {
return nil, xerrors.Errorf("actor code is not init: %s", name)
return nil, fmt.Errorf("actor code is not init: %s", name)
}

switch av {
Expand All @@ -53,7 +53,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
{{end}}
}

return nil, xerrors.Errorf("unknown actor code %s", act.Code)
return nil, fmt.Errorf("unknown actor code %s", act.Code)
}

func MakeState(store adt.Store, av actorstypes.Version, networkName string) (State, error) {
Expand All @@ -63,7 +63,7 @@ func MakeState(store adt.Store, av actorstypes.Version, networkName string) (Sta
return make{{.}}(store, networkName)
{{end}}
}
return nil, xerrors.Errorf("unknown actor version %d", av)
return nil, fmt.Errorf("unknown actor version %d", av)
}

type State interface {
Expand Down
6 changes: 3 additions & 3 deletions venus-shared/actors/builtin/init/state.sep.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"fmt"

"github.com/filecoin-project/venus/venus-shared/actors/adt"

Expand Down Expand Up @@ -105,12 +105,12 @@ func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) {
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
return fmt.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
Expand Down
7 changes: 4 additions & 3 deletions venus-shared/actors/builtin/init/state.v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package init

import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus/venus-shared/actors/adt"

Expand Down Expand Up @@ -88,12 +89,12 @@ func (s *state0) Remove(addrs ...address.Address) (err error) {
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
return fmt.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
Expand Down
7 changes: 4 additions & 3 deletions venus-shared/actors/builtin/init/state.v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package init

import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus/venus-shared/actors/adt"

Expand Down Expand Up @@ -88,12 +89,12 @@ func (s *state2) Remove(addrs ...address.Address) (err error) {
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
return fmt.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
Expand Down
7 changes: 4 additions & 3 deletions venus-shared/actors/builtin/init/state.v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package init

import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus/venus-shared/actors/adt"

Expand Down Expand Up @@ -90,12 +91,12 @@ func (s *state3) Remove(addrs ...address.Address) (err error) {
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
return fmt.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
Expand Down
7 changes: 4 additions & 3 deletions venus-shared/actors/builtin/init/state.v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package init

import (
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/venus/venus-shared/actors/adt"

Expand Down Expand Up @@ -90,12 +91,12 @@ func (s *state4) Remove(addrs ...address.Address) (err error) {
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
return fmt.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
Expand Down
Loading

0 comments on commit bfbc6d4

Please sign in to comment.