Skip to content

Commit

Permalink
refactor: use errors.New to replace fmt.Errorf with no parameters (#2320
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ChengenH authored Dec 17, 2024
1 parent a9d11d4 commit c4d10f9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/juno/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

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

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

database, err := pebble.New(path)
Expand Down
3 changes: 2 additions & 1 deletion core/trie/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package trie
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"math/big"

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

keyCopy := k.Copy()
Expand Down
2 changes: 1 addition & 1 deletion core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *StorageNodeSet) Get(key Key) (*StorageNode, bool) {
// Put adds a new StorageNode or updates an existing one.
func (s *StorageNodeSet) Put(key Key, node *StorageNode) error {
if node == nil {
return fmt.Errorf("cannot put nil node")
return errors.New("cannot put nil node")
}

// If key exists, update the node
Expand Down
7 changes: 3 additions & 4 deletions p2p/starknet/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package starknet

import (
"errors"
"fmt"

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

func newIteratorByNumber(bcReader blockchain.Reader, blockNumber, limit, step uint64, forward bool) (*iterator, error) {
if step == 0 {
return nil, fmt.Errorf("step is zero")
return nil, errors.New("step is zero")
}
if limit == 0 {
return nil, fmt.Errorf("limit is zero")
return nil, errors.New("limit is zero")
}

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

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

block, err := bcReader.BlockByHash(blockHash)
Expand Down
3 changes: 2 additions & 1 deletion rpc/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

import (
"context"
"errors"
"fmt"
"math/big"

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

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

receipt, err := h.l1Client.TransactionReceipt(ctx, *txHash)
Expand Down
2 changes: 1 addition & 1 deletion rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (h *Handler) AddTransaction(ctx context.Context, tx BroadcastedTransaction)
}, nil
}

var errTransactionNotFound = fmt.Errorf("transaction not found")
var errTransactionNotFound = errors.New("transaction not found")

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

0 comments on commit c4d10f9

Please sign in to comment.