From 84b7a704b96e013564b955ac20e5e761e14c6c40 Mon Sep 17 00:00:00 2001 From: RiceChuan Date: Thu, 12 Dec 2024 17:32:48 +0800 Subject: [PATCH] chore: use errors.New to replace fmt.Errorf with no parameters Signed-off-by: RiceChuan --- main_test.go | 3 ++- types/address.go | 5 ++--- types/digest_item.go | 7 +++---- types/metadata.go | 11 ++++++----- types/metadataV10.go | 2 +- types/metadataV7.go | 3 ++- types/uint.go | 3 ++- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/main_test.go b/main_test.go index de2aeca58..440536ab5 100644 --- a/main_test.go +++ b/main_test.go @@ -17,6 +17,7 @@ package gsrpc_test import ( + "errors" "fmt" "github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic" "math/big" @@ -207,7 +208,7 @@ func Example_makeASimpleTransfer() { // 1 unit of transfer bal, ok := new(big.Int).SetString("100000000000000", 10) if !ok { - panic(fmt.Errorf("failed to convert balance")) + panic(errors.New("failed to convert balance")) } c, err := types.NewCall(meta, "Balances.transfer", bob, types.NewUCompact(bal)) diff --git a/types/address.go b/types/address.go index 9783676a2..1077e788e 100644 --- a/types/address.go +++ b/types/address.go @@ -17,8 +17,7 @@ package types import ( - "fmt" - + "errors" "github.com/centrifuge/go-substrate-rpc-client/v4/scale" "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" ) @@ -91,7 +90,7 @@ func (a *Address) Decode(decoder scale.Decoder) error { } if b == 0xfe { - return fmt.Errorf("decoding of Address with 0xfe prefix not supported") + return errors.New("decoding of Address with 0xfe prefix not supported") } if b == 0xfd { diff --git a/types/digest_item.go b/types/digest_item.go index 9e204a20e..754107a33 100644 --- a/types/digest_item.go +++ b/types/digest_item.go @@ -17,8 +17,7 @@ package types import ( - "fmt" - + "errors" "github.com/centrifuge/go-substrate-rpc-client/v4/scale" ) @@ -151,7 +150,7 @@ func (c ChangesTrieSignal) Encode(encoder scale.Encoder) error { return err } default: - return fmt.Errorf("no such variant for ChangesTrieSignal") + return errors.New("no such variant for ChangesTrieSignal") } return nil @@ -171,7 +170,7 @@ func (c *ChangesTrieSignal) Decode(decoder scale.Decoder) error { return err } default: - return fmt.Errorf("no such variant for ChangesTrieSignal") + return errors.New("no such variant for ChangesTrieSignal") } return nil diff --git a/types/metadata.go b/types/metadata.go index 74e6c25bb..282285970 100644 --- a/types/metadata.go +++ b/types/metadata.go @@ -17,6 +17,7 @@ package types import ( + "errors" "fmt" "hash" "strings" @@ -240,7 +241,7 @@ func (m *Metadata) FindConstantValue(module string, constantName string) ([]byte case 14: return m.AsMetadataV14.FindConstantValue(txtModule, txtConstantName) default: - return nil, fmt.Errorf("unsupported metadata version") + return nil, errors.New("unsupported metadata version") } } @@ -265,7 +266,7 @@ func (m *Metadata) FindCallIndex(call string) (CallIndex, error) { case 14: return m.AsMetadataV14.FindCallIndex(call) default: - return CallIndex{}, fmt.Errorf("unsupported metadata version") + return CallIndex{}, errors.New("unsupported metadata version") } } @@ -290,7 +291,7 @@ func (m *Metadata) FindEventNamesForEventID(eventID EventID) (Text, Text, error) case 14: return m.AsMetadataV14.FindEventNamesForEventID(eventID) default: - return "", "", fmt.Errorf("unsupported metadata version") + return "", "", errors.New("unsupported metadata version") } } @@ -315,7 +316,7 @@ func (m *Metadata) FindStorageEntryMetadata(module string, fn string) (StorageEn case 14: return m.AsMetadataV14.FindStorageEntryMetadata(module, fn) default: - return nil, fmt.Errorf("unsupported metadata version") + return nil, errors.New("unsupported metadata version") } } @@ -351,5 +352,5 @@ func DefaultPlainHasher(entry StorageEntryMetadata) (hash.Hash, error) { return xxhash.New128(nil), nil } - return nil, fmt.Errorf("Hasher() is only to be called on a Plain entry") + return nil, errors.New("Hasher() is only to be called on a Plain entry") } diff --git a/types/metadataV10.go b/types/metadataV10.go index 6601a1e57..140488bbc 100644 --- a/types/metadataV10.go +++ b/types/metadataV10.go @@ -233,7 +233,7 @@ func (s StorageFunctionMetadataV10) IsMap() bool { func (s StorageFunctionMetadataV10) Hashers() ([]hash.Hash, error) { if !s.IsMap() { - return nil, fmt.Errorf("Hashers() is only to be called on Maps") + return nil, errors.New("Hashers() is only to be called on Maps") } var hashers = collectHashersV10(s.Type) diff --git a/types/metadataV7.go b/types/metadataV7.go index af938b3d8..58764ca9c 100644 --- a/types/metadataV7.go +++ b/types/metadataV7.go @@ -17,6 +17,7 @@ package types import ( + "errors" "fmt" "hash" "strings" @@ -220,7 +221,7 @@ func (s StorageFunctionMetadataV5) IsMap() bool { func (s StorageFunctionMetadataV5) Hashers() ([]hash.Hash, error) { if !s.IsMap() { - return nil, fmt.Errorf("Hashers() is only to be called on Maps") + return nil, errors.New("Hashers() is only to be called on Maps") } var hashers = collectHashersV5(s.Type) diff --git a/types/uint.go b/types/uint.go index 49c102fd1..471478742 100644 --- a/types/uint.go +++ b/types/uint.go @@ -18,6 +18,7 @@ package types import ( "encoding/json" + "errors" "fmt" "math/big" @@ -237,7 +238,7 @@ func (i U256) Encode(encoder scale.Encoder) error { // length could hold func BigIntToUintBytes(i *big.Int, bytelen int) ([]byte, error) { if i.Sign() < 0 { - return nil, fmt.Errorf("cannot encode a negative big.Int into an unsigned integer") + return nil, errors.New("cannot encode a negative big.Int into an unsigned integer") } max := big.NewInt(0).Exp(big.NewInt(2), big.NewInt(int64(bytelen*8)), nil)