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

perf: use errors.New to replace fmt.Errorf with no parameters #377

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"
"math/big"
"time"
Expand Down Expand Up @@ -206,7 +207,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
4 changes: 2 additions & 2 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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 +91,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
4 changes: 2 additions & 2 deletions types/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package types

import (
"fmt"
"errors"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
)
Expand All @@ -42,7 +42,7 @@ func (b BytesBare) Encode(encoder scale.Encoder) error {

// Decode does nothing and always returns an error. BytesBare is only used for encoding, not for decoding
func (b *BytesBare) Decode(decoder scale.Decoder) error {
return fmt.Errorf("decoding of BytesBare is not supported")
return errors.New("decoding of BytesBare is not supported")
}

// Bytes8 represents an 8 byte array
Expand Down
5 changes: 2 additions & 3 deletions types/digest_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package types

import (
"fmt"

"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
4 changes: 2 additions & 2 deletions types/extrinsic_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package types

import (
"fmt"
"errors"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (e ExtrinsicPayloadV3) Encode(encoder scale.Encoder) error {

// Decode does nothing and always returns an error. ExtrinsicPayloadV3 is only used for encoding, not for decoding
func (e *ExtrinsicPayloadV3) Decode(decoder scale.Decoder) error {
return fmt.Errorf("decoding of ExtrinsicPayloadV3 is not supported")
return errors.New("decoding of ExtrinsicPayloadV3 is not supported")
}

type ExtrinsicPayloadV4 struct {
Expand Down
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
4 changes: 2 additions & 2 deletions types/moment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package types

import (
"fmt"
"errors"
"math"
"time"

Expand Down Expand Up @@ -48,7 +48,7 @@ func (m *Moment) Decode(decoder scale.Decoder) error {

// Error in case of overflow
if u > math.MaxInt64 {
return fmt.Errorf("cannot decode a uint64 into a Moment if it overflows int64")
return errors.New("cannot decode a uint64 into a Moment if it overflows int64")
}

secs := u / MillisInSecond
Expand Down
3 changes: 2 additions & 1 deletion types/storage_change_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package types

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

"github.com/centrifuge/go-substrate-rpc-client/v4/types/codec"
Expand All @@ -42,7 +43,7 @@ func (r *KeyValueOption) UnmarshalJSON(b []byte) error {
}
switch len(tmp) {
case 0:
return fmt.Errorf("expected at least one entry for KeyValueOption")
return errors.New("expected at least one entry for KeyValueOption")
case 2:
r.HasStorageData = true
data, err := codec.HexDecodeString(tmp[1])
Expand Down
3 changes: 2 additions & 1 deletion types/storage_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package types

import (
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -56,7 +57,7 @@ func CreateStorageKey(meta *Metadata, prefix, method string, args ...[]byte) (St

for i := nonNilCount; i < len(args); i++ {
if len(args[i]) != 0 {
return nil, fmt.Errorf("non-nil arguments cannot be preceded by nil arguments")
return nil, errors.New("non-nil arguments cannot be preceded by nil arguments")
}
}

Expand Down