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

refactor: use errors.New to replace fmt.Errorf with no parameters #2320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 cmd/juno/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand Down Expand Up @@ -265,7 +266,7 @@
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")

Check warning on line 269 in cmd/juno/dbcmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/juno/dbcmd.go#L269

Added line #L269 was not covered by tests
}

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 @@
// 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")

Check warning on line 194 in core/trie/trie.go

View check run for this annotation

Codecov / codecov/patch

core/trie/trie.go#L194

Added line #L194 was not covered by tests
}

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

import (
"errors"
"fmt"

"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
Expand All @@ -23,10 +21,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 +39,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 @@

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

Expand Down Expand Up @@ -81,7 +82,7 @@

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"))

Check warning on line 85 in rpc/l1.go

View check run for this annotation

Codecov / codecov/patch

rpc/l1.go#L85

Added line #L85 was not covered by tests
}

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
Loading