Skip to content

Commit

Permalink
Merge pull request #6438 from RiceChuan/master
Browse files Browse the repository at this point in the history
chore: use errors.New to replace fmt.Errorf with no parameters
  • Loading branch information
simlecode authored Dec 20, 2024
2 parents 86b2905 + 5746ca7 commit 50879c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions app/submodule/chain/chaininfo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (cia *chainInfoAPI) StateGetBeaconEntry(ctx context.Context, epoch abi.Chai
select {
case be, ok := <-e:
if !ok {
return nil, fmt.Errorf("beacon get returned no value")
return nil, errors.New("beacon get returned no value")
}
if be.Err != nil {
return nil, be.Err
Expand Down Expand Up @@ -798,7 +798,7 @@ func (cia *chainInfoAPI) ChainGetGenesis(ctx context.Context) (*types.TipSet, er
func (cia *chainInfoAPI) StateActorManifestCID(ctx context.Context, nv network.Version) (cid.Cid, error) {
actorVersion, err := actorstypes.VersionForNetwork(nv)
if err != nil {
return cid.Undef, fmt.Errorf("invalid network version")
return cid.Undef, errors.New("invalid network version")
}

c, ok := actors.GetManifest(actorVersion)
Expand Down Expand Up @@ -915,7 +915,7 @@ func (cia *chainInfoAPI) ChainGetEvents(ctx context.Context, root cid.Cid) ([]ty
var evt types.Event
err = evtArr.ForEach(ctx, func(u uint64, deferred *cbg.Deferred) error {
if u > math.MaxInt {
return fmt.Errorf("too many events")
return errors.New("too many events")
}
if err := evt.UnmarshalCBOR(bytes.NewReader(deferred.Raw)); err != nil {
return err
Expand Down
34 changes: 17 additions & 17 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (a *ethAPI) EthGetBlockByHash(ctx context.Context, blkHash types.EthHash, f

func (a *ethAPI) parseBlkParam(ctx context.Context, blkParam string, strict bool) (tipset *types.TipSet, err error) {
if blkParam == "earliest" {
return nil, fmt.Errorf("block param \"earliest\" is not supported")
return nil, errors.New("block param \"earliest\" is not supported")
}

head, err := a.chain.ChainHead(ctx)
Expand All @@ -250,7 +250,7 @@ func (a *ethAPI) parseBlkParam(ctx context.Context, blkParam string, strict bool
case "latest":
parent, err := a.chain.ChainGetTipSet(ctx, head.Parents())
if err != nil {
return nil, fmt.Errorf("cannot get parent tipset")
return nil, errors.New("cannot get parent tipset")
}
return parent, nil
default:
Expand All @@ -260,7 +260,7 @@ func (a *ethAPI) parseBlkParam(ctx context.Context, blkParam string, strict bool
return nil, fmt.Errorf("cannot parse block number: %v", err)
}
if abi.ChainEpoch(num) > head.Height()-1 {
return nil, fmt.Errorf("requested a future epoch (beyond 'latest')")
return nil, errors.New("requested a future epoch (beyond 'latest')")
}
ts, err := a.chain.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(num), head.Key())
if err != nil {
Expand Down Expand Up @@ -570,7 +570,7 @@ func (a *ethAPI) EthGetCode(ctx context.Context, ethAddr types.EthAddress, blkPa

// StateManager.Call will panic if there is no parent
if ts.Height() == 0 {
return nil, fmt.Errorf("block param must not specify genesis block")
return nil, errors.New("block param must not specify genesis block")
}

actor, err := a.em.chainModule.Stmgr.GetActorAt(ctx, to, ts)
Expand Down Expand Up @@ -616,7 +616,7 @@ func (a *ethAPI) EthGetCode(ctx context.Context, ethAddr types.EthAddress, blkPa
}

if res.MsgRct == nil {
return nil, fmt.Errorf("no message receipt")
return nil, errors.New("no message receipt")
}

if res.MsgRct.ExitCode.IsError() {
Expand Down Expand Up @@ -649,7 +649,7 @@ func (a *ethAPI) EthGetStorageAt(ctx context.Context, ethAddr types.EthAddress,

l := len(position)
if l > 32 {
return nil, fmt.Errorf("supplied storage key is too long")
return nil, errors.New("supplied storage key is too long")
}

// pad with zero bytes if smaller than 32 bytes
Expand Down Expand Up @@ -714,7 +714,7 @@ func (a *ethAPI) EthGetStorageAt(ctx context.Context, ethAddr types.EthAddress,
}

if res.MsgRct == nil {
return nil, fmt.Errorf("no message receipt")
return nil, errors.New("no message receipt")
}

if res.MsgRct.ExitCode.IsError() {
Expand Down Expand Up @@ -806,7 +806,7 @@ func (a *ethAPI) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (types.
return types.EthFeeHistory{}, fmt.Errorf("decoding params: %w", err)
}
if params.BlkCount > 1024 {
return types.EthFeeHistory{}, fmt.Errorf("block count should be smaller than 1024")
return types.EthFeeHistory{}, errors.New("block count should be smaller than 1024")
}
rewardPercentiles := make([]float64, 0)
if params.RewardPercentiles != nil {
Expand Down Expand Up @@ -1264,7 +1264,7 @@ func (a *ethAPI) EthTraceBlock(ctx context.Context, blkNum string) ([]*types.Eth

func (a *ethAPI) EthTraceReplayBlockTransactions(ctx context.Context, blkNum string, traceTypes []string) ([]*types.EthTraceReplayBlockTransaction, error) {
if len(traceTypes) != 1 || traceTypes[0] != "trace" {
return nil, fmt.Errorf("only 'trace' is supported")
return nil, errors.New("only 'trace' is supported")
}

ts, err := getTipsetByBlockNumber(ctx, a.em.chainModule.ChainReader, blkNum, false)
Expand Down Expand Up @@ -1343,12 +1343,12 @@ func (a *ethAPI) EthTraceTransaction(ctx context.Context, txHash string) ([]*typ
}

if tx == nil {
return nil, fmt.Errorf("transaction not found")
return nil, errors.New("transaction not found")
}

// tx.BlockNumber is nil when the transaction is still in the mpool/pending
if tx.BlockNumber == nil {
return nil, fmt.Errorf("no trace for pending transactions")
return nil, errors.New("no trace for pending transactions")
}

blockTraces, err := a.EthTraceBlock(ctx, strconv.FormatUint(uint64(*tx.BlockNumber), 10))
Expand Down Expand Up @@ -1386,13 +1386,13 @@ func (a *ethAPI) EthTraceFilter(ctx context.Context, filter types.EthTraceFilter

switch blockValue {
case "earliest":
return 0, fmt.Errorf("block param \"earliest\" is not supported")
return 0, errors.New("block param \"earliest\" is not supported")
case "pending":
return types.EthUint64(head.Height()), nil
case "latest":
parent, err := a.em.chainModule.ChainReader.GetTipSet(ctx, head.Parents())
if err != nil {
return 0, fmt.Errorf("cannot get parent tipset")
return 0, errors.New("cannot get parent tipset")
}
return types.EthUint64(parent.Height()), nil
case "safe":
Expand Down Expand Up @@ -1486,23 +1486,23 @@ func matchFilterCriteria(trace *types.EthTraceBlock, fromDecodedAddresses []type
case "call":
action, ok := trace.Action.(*types.EthCallTraceAction)
if !ok {
return false, fmt.Errorf("invalid call trace action")
return false, errors.New("invalid call trace action")
}
traceTo = action.To
traceFrom = action.From
case "create":
result, okResult := trace.Result.(*types.EthCreateTraceResult)
if !okResult {
return false, fmt.Errorf("invalid create trace result")
return false, errors.New("invalid create trace result")
}

action, okAction := trace.Action.(*types.EthCreateTraceAction)
if !okAction {
return false, fmt.Errorf("invalid create trace action")
return false, errors.New("invalid create trace action")
}

if result.Address == nil {
return false, fmt.Errorf("address is nil in create trace result")
return false, errors.New("address is nil in create trace result")
}

traceTo = *result.Address
Expand Down
16 changes: 8 additions & 8 deletions app/submodule/eth/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {

func getTipsetByBlockNumber(ctx context.Context, store *chain.Store, blkParam string, strict bool) (*types.TipSet, error) {
if blkParam == "earliest" {
return nil, fmt.Errorf("block param \"earliest\" is not supported")
return nil, errors.New("block param \"earliest\" is not supported")
}

head := store.GetHead()
Expand All @@ -51,7 +51,7 @@ func getTipsetByBlockNumber(ctx context.Context, store *chain.Store, blkParam st
case "latest":
parent, err := store.GetTipSet(ctx, head.Parents())
if err != nil {
return nil, fmt.Errorf("cannot get parent tipset")
return nil, errors.New("cannot get parent tipset")
}
return parent, nil
case "safe":
Expand All @@ -77,7 +77,7 @@ func getTipsetByBlockNumber(ctx context.Context, store *chain.Store, blkParam st
return nil, fmt.Errorf("cannot parse block number: %v", err)
}
if abi.ChainEpoch(num) > head.Height()-1 {
return nil, fmt.Errorf("requested a future epoch (beyond 'latest')")
return nil, errors.New("requested a future epoch (beyond 'latest')")
}
ts, err := store.GetTipSetByHeight(ctx, head, abi.ChainEpoch(num), true)
if err != nil {
Expand All @@ -96,13 +96,13 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, store *chain.Store, bl
predefined := blkParam.PredefinedBlock
if predefined != nil {
if *predefined == "earliest" {
return nil, fmt.Errorf("block param \"earliest\" is not supported")
return nil, errors.New("block param \"earliest\" is not supported")
} else if *predefined == "pending" {
return head, nil
} else if *predefined == "latest" {
parent, err := store.GetTipSet(ctx, head.Parents())
if err != nil {
return nil, fmt.Errorf("cannot get parent tipset")
return nil, errors.New("cannot get parent tipset")
}
return parent, nil
} else {
Expand All @@ -113,7 +113,7 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, store *chain.Store, bl
if blkParam.BlockNumber != nil {
height := abi.ChainEpoch(*blkParam.BlockNumber)
if height > head.Height()-1 {
return nil, fmt.Errorf("requested a future epoch (beyond 'latest')")
return nil, errors.New("requested a future epoch (beyond 'latest')")
}
ts, err := store.GetTipSetByHeight(ctx, head, height, true)
if err != nil {
Expand All @@ -138,7 +138,7 @@ func getTipsetByEthBlockNumberOrHash(ctx context.Context, store *chain.Store, bl

// verify that it equals the expected tipset
if !walkTS.Equals(ts) {
return nil, fmt.Errorf("tipset is not canonical")
return nil, errors.New("tipset is not canonical")
}
}

Expand Down Expand Up @@ -644,7 +644,7 @@ func newEthTxFromMessageLookup(ctx context.Context, msgLookup *types.MsgLookup,
}
}
if txIdx < 0 {
return types.EthTx{}, fmt.Errorf("cannot find the msg in the tipset")
return types.EthTx{}, errors.New("cannot find the msg in the tipset")
}
}

Expand Down

0 comments on commit 50879c6

Please sign in to comment.