Skip to content

Commit c4d10f9

Browse files
authored
refactor: use errors.New to replace fmt.Errorf with no parameters (#2320)
1 parent a9d11d4 commit c4d10f9

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

cmd/juno/dbcmd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"os"
78

@@ -265,7 +266,7 @@ func getNetwork(head *core.Block, stateDiff *core.StateDiff) string {
265266
func openDB(path string) (db.DB, error) {
266267
_, err := os.Stat(path)
267268
if os.IsNotExist(err) {
268-
return nil, fmt.Errorf("database path does not exist")
269+
return nil, errors.New("database path does not exist")
269270
}
270271

271272
database, err := pebble.New(path)

core/trie/key.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package trie
33
import (
44
"bytes"
55
"encoding/hex"
6+
"errors"
67
"fmt"
78
"math/big"
89

@@ -111,7 +112,7 @@ func (k *Key) shiftRight(n uint8) {
111112
// MostSignificantBits returns a new key with the most significant n bits of the current key.
112113
func (k *Key) MostSignificantBits(n uint8) (*Key, error) {
113114
if n > k.len {
114-
return nil, fmt.Errorf("cannot get more bits than the key length")
115+
return nil, errors.New("cannot get more bits than the key length")
115116
}
116117

117118
keyCopy := k.Copy()

core/trie/trie.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (s *StorageNodeSet) Get(key Key) (*StorageNode, bool) {
191191
// Put adds a new StorageNode or updates an existing one.
192192
func (s *StorageNodeSet) Put(key Key, node *StorageNode) error {
193193
if node == nil {
194-
return fmt.Errorf("cannot put nil node")
194+
return errors.New("cannot put nil node")
195195
}
196196

197197
// If key exists, update the node

p2p/starknet/iterator.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package starknet
22

33
import (
44
"errors"
5-
"fmt"
65

76
"github.com/NethermindEth/juno/blockchain"
87
"github.com/NethermindEth/juno/core"
@@ -23,10 +22,10 @@ type iterator struct {
2322

2423
func newIteratorByNumber(bcReader blockchain.Reader, blockNumber, limit, step uint64, forward bool) (*iterator, error) {
2524
if step == 0 {
26-
return nil, fmt.Errorf("step is zero")
25+
return nil, errors.New("step is zero")
2726
}
2827
if limit == 0 {
29-
return nil, fmt.Errorf("limit is zero")
28+
return nil, errors.New("limit is zero")
3029
}
3130

3231
return &iterator{
@@ -41,7 +40,7 @@ func newIteratorByNumber(bcReader blockchain.Reader, blockNumber, limit, step ui
4140

4241
func newIteratorByHash(bcReader blockchain.Reader, blockHash *felt.Felt, limit, step uint64, forward bool) (*iterator, error) {
4342
if blockHash == nil {
44-
return nil, fmt.Errorf("block hash is nil")
43+
return nil, errors.New("block hash is nil")
4544
}
4645

4746
block, err := bcReader.BlockByHash(blockHash)

rpc/l1.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rpc
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"math/big"
78

@@ -81,7 +82,7 @@ func (h *Handler) GetMessageStatus(ctx context.Context, l1TxnHash *common.Hash)
8182

8283
func (h *Handler) messageToL2Logs(ctx context.Context, txHash *common.Hash) ([]*common.Hash, *jsonrpc.Error) {
8384
if h.l1Client == nil {
84-
return nil, jsonrpc.Err(jsonrpc.InternalError, fmt.Errorf("11 client not found, cannot serve starknet_getMessage"))
85+
return nil, jsonrpc.Err(jsonrpc.InternalError, errors.New("11 client not found, cannot serve starknet_getMessage"))
8586
}
8687

8788
receipt, err := h.l1Client.TransactionReceipt(ctx, *txHash)

rpc/transaction.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func (h *Handler) AddTransaction(ctx context.Context, tx BroadcastedTransaction)
609609
}, nil
610610
}
611611

612-
var errTransactionNotFound = fmt.Errorf("transaction not found")
612+
var errTransactionNotFound = errors.New("transaction not found")
613613

614614
func (h *Handler) TransactionStatus(ctx context.Context, hash felt.Felt) (*TransactionStatus, *jsonrpc.Error) {
615615
receipt, txErr := h.TransactionReceiptByHash(hash)

0 commit comments

Comments
 (0)