Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package gsrpc_test

import (
"errors"
"fmt"
"github.com/centrifuge/go-substrate-rpc-client/v4/types/extrinsic"
"math/big"
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions types/digest_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package types

import (
"fmt"

"errors"
"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package types

import (
"errors"
"fmt"
"hash"
"strings"
Expand Down Expand Up @@ -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")
}
}

Expand All @@ -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")
}
}

Expand All @@ -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")
}
}

Expand All @@ -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")
}
}

Expand Down Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion types/metadataV10.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion types/metadataV7.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package types

import (
"errors"
"fmt"
"hash"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion types/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package types

import (
"encoding/json"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -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)
Expand Down