From b4903ccb4960f131e4f471fd853fcbc30c4c6dca Mon Sep 17 00:00:00 2001 From: RiceChuan Date: Sat, 21 Dec 2024 18:14:23 +0800 Subject: [PATCH] chore: suggest using errors.New instead of fmt.Errorf with no parameters Signed-off-by: RiceChuan --- eth/rpc/types.go | 7 ++++--- hmy/tracers/tracer.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eth/rpc/types.go b/eth/rpc/types.go index 894834885a..9e5aff28e3 100644 --- a/eth/rpc/types.go +++ b/eth/rpc/types.go @@ -19,6 +19,7 @@ package rpc import ( "context" "encoding/json" + "errors" "fmt" "math" "strings" @@ -97,7 +98,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error { return err } if blckNum > math.MaxInt64 { - return fmt.Errorf("block number larger than int64") + return errors.New("block number larger than int64") } *bn = BlockNumber(blckNum) return nil @@ -135,7 +136,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { err := json.Unmarshal(data, &e) if err == nil { if e.BlockNumber != nil && e.BlockHash != nil { - return fmt.Errorf("cannot specify both BlockHash and BlockNumber, choose one or the other") + return errors.New("cannot specify both BlockHash and BlockNumber, choose one or the other") } bnh.BlockNumber = e.BlockNumber bnh.BlockHash = e.BlockHash @@ -180,7 +181,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { return err } if blckNum > math.MaxInt64 { - return fmt.Errorf("blocknumber too high") + return errors.New("blocknumber too high") } bn := BlockNumber(blckNum) bnh.BlockNumber = &bn diff --git a/hmy/tracers/tracer.go b/hmy/tracers/tracer.go index bc349a5147..f44e14c8a8 100644 --- a/hmy/tracers/tracer.go +++ b/hmy/tracers/tracer.go @@ -428,17 +428,17 @@ func New(code string) (*Tracer, error) { tracer.tracerObject = 0 // yeah, nice, eval can't return the index itself if !tracer.vm.GetPropString(tracer.tracerObject, "step") { - return nil, fmt.Errorf("trace object must expose a function step()") + return nil, errors.New("trace object must expose a function step()") } tracer.vm.Pop() if !tracer.vm.GetPropString(tracer.tracerObject, "fault") { - return nil, fmt.Errorf("trace object must expose a function fault()") + return nil, errors.New("trace object must expose a function fault()") } tracer.vm.Pop() if !tracer.vm.GetPropString(tracer.tracerObject, "result") { - return nil, fmt.Errorf("trace object must expose a function result()") + return nil, errors.New("trace object must expose a function result()") } tracer.vm.Pop()