Skip to content

Commit 9979590

Browse files
authored
fix: use errors.New for const errors (#181)
1 parent b715333 commit 9979590

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252
ErrNotFound = errors.New("header: not found")
5353

5454
// ErrNoHead is returned when Store is empty (does not contain any known header).
55-
ErrNoHead = fmt.Errorf("header/store: no chain head")
55+
ErrNoHead = errors.New("header/store: no chain head")
5656

5757
// ErrHeadersLimitExceeded is returned when ExchangeServer receives header request for more
5858
// than maxRequestSize headers.

p2p/exchange.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (ex *Exchange[H]) GetByHeight(ctx context.Context, height uint64) (H, error
261261
var zero H
262262
// sanity check height
263263
if height == 0 {
264-
err := fmt.Errorf("specified request height must be greater than 0")
264+
err := errors.New("specified request height must be greater than 0")
265265
span.SetStatus(codes.Error, err.Error())
266266
return zero, err
267267
}
@@ -349,7 +349,7 @@ func (ex *Exchange[H]) performRequest(
349349

350350
trustedPeers := ex.trustedPeers()
351351
if len(trustedPeers) == 0 {
352-
return nil, fmt.Errorf("no trusted peers")
352+
return nil, errors.New("no trusted peers")
353353
}
354354

355355
var reqErr error

p2p/subscriber.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package p2p
33
import (
44
"context"
55
"errors"
6-
"fmt"
76

87
pubsub "github.com/libp2p/go-libp2p-pubsub"
98
"github.com/libp2p/go-libp2p/core/peer"
@@ -153,7 +152,7 @@ func (s *Subscriber[H]) SetVerifier(val func(context.Context, H) error) error {
153152
// topic.
154153
func (s *Subscriber[H]) Subscribe() (header.Subscription[H], error) {
155154
if s.topic == nil {
156-
return nil, fmt.Errorf("header topic is not instantiated, service must be started before subscribing")
155+
return nil, errors.New("header topic is not instantiated, service must be started before subscribing")
157156
}
158157

159158
return newSubscription[H](s.topic, s.metrics)

store/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func newStore[H header.Header[H]](ds datastore.Batching, opts ...Option) (*Store
128128

129129
func (s *Store[H]) Init(ctx context.Context, initial H) error {
130130
if s.heightSub.Height() != 0 {
131-
return fmt.Errorf("store already initialized")
131+
return errors.New("store already initialized")
132132
}
133133
// trust the given header as the initial head
134134
err := s.flush(ctx, initial)
@@ -223,7 +223,7 @@ func (s *Store[H]) Get(ctx context.Context, hash header.Hash) (H, error) {
223223
func (s *Store[H]) GetByHeight(ctx context.Context, height uint64) (H, error) {
224224
var zero H
225225
if height == 0 {
226-
return zero, fmt.Errorf("header/store: height must be bigger than zero")
226+
return zero, errors.New("header/store: height must be bigger than zero")
227227
}
228228
// if the requested 'height' was not yet published
229229
// we subscribe to it

sync/sync_getter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package sync
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"sync"
77
"sync/atomic"
88
"testing"
@@ -41,7 +41,7 @@ func TestSyncGetterHead(t *testing.T) {
4141
assert.EqualValues(t, 1, fex.hits.Load())
4242
}
4343

44-
var errFakeHead = fmt.Errorf("head")
44+
var errFakeHead = errors.New("head")
4545

4646
type fakeGetter[H header.Header[H]] struct {
4747
hits atomic.Uint32

0 commit comments

Comments
 (0)