Skip to content

Commit 26cbf73

Browse files
committed
all: run perfsprint
1 parent ba5ba1a commit 26cbf73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+161
-142
lines changed

bitswap/bitswap_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bitswap_test
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"os"
89
"sync"
@@ -432,10 +433,10 @@ func TestBasicBitswap(t *testing.T) {
432433
// peer should no longer keep second peer's want
433434
if err = tu.WaitFor(ctx, func() error {
434435
if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 {
435-
return fmt.Errorf("should have no items in other peers wantlist")
436+
return errors.New("should have no items in other peers wantlist")
436437
}
437438
if len(instances[1].Exchange.GetWantlist()) != 0 {
438-
return fmt.Errorf("shouldnt have anything in wantlist")
439+
return errors.New("shouldnt have anything in wantlist")
439440
}
440441
return nil
441442
}); err != nil {

bitswap/client/bitswap_with_sessions_test.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"testing"
78
"time"
@@ -489,7 +490,7 @@ func TestWantlistClearsOnCancel(t *testing.T) {
489490

490491
if err := tu.WaitFor(ctx, func() error {
491492
if len(a.Exchange.GetWantlist()) > 0 {
492-
return fmt.Errorf("expected empty wantlist")
493+
return errors.New("expected empty wantlist")
493494
}
494495
return nil
495496
}); err != nil {

bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package messagequeue
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"sync"
77
"testing"
88
"time"
@@ -342,7 +342,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
342342
tr := timeoutRecorder{}
343343
clock := clock.NewMock()
344344
pinged := make(chan struct{})
345-
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: fmt.Errorf("ping error")}
345+
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: errors.New("ping error")}
346346
timeoutsTriggered := make(chan struct{})
347347

348348
dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout,

bitswap/client/internal/messagequeue/messagequeue_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package messagequeue
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"math"
77
"math/rand"
88
"sync"
@@ -40,7 +40,7 @@ func (fmn *fakeMessageNetwork) NewMessageSender(context.Context, peer.ID, *bsnet
4040
func (fms *fakeMessageNetwork) Self() peer.ID { return "" }
4141
func (fms *fakeMessageNetwork) Latency(peer.ID) time.Duration { return 0 }
4242
func (fms *fakeMessageNetwork) Ping(context.Context, peer.ID) ping.Result {
43-
return ping.Result{Error: fmt.Errorf("ping error")}
43+
return ping.Result{Error: errors.New("ping error")}
4444
}
4545

4646
type fakeDontHaveTimeoutMgr struct {

bitswap/client/internal/providerquerymanager/providerquerymanager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (rpm *receivedProviderMessage) handle(pqm *ProviderQueryManager) {
355355
}
356356

357357
func (fpqm *finishedProviderQueryMessage) debugMessage() string {
358-
return fmt.Sprintf("Finished Provider Query on cid: %s", fpqm.k.String())
358+
return "Finished Provider Query on cid: " + fpqm.k.String()
359359
}
360360

361361
func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) {
@@ -372,7 +372,7 @@ func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) {
372372
}
373373

374374
func (npqm *newProvideQueryMessage) debugMessage() string {
375-
return fmt.Sprintf("New Provider Query on cid: %s", npqm.k.String())
375+
return "New Provider Query on cid: " + npqm.k.String()
376376
}
377377

378378
func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
@@ -407,7 +407,7 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) {
407407
}
408408

409409
func (crm *cancelRequestMessage) debugMessage() string {
410-
return fmt.Sprintf("Cancel provider query on cid: %s", crm.k.String())
410+
return "Cancel provider query on cid: " + crm.k.String()
411411
}
412412

413413
func (crm *cancelRequestMessage) handle(pqm *ProviderQueryManager) {

bitswap/client/internal/sessionmanager/sessionmanager_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package sessionmanager
22

33
import (
44
"context"
5-
"fmt"
5+
"strconv"
66
"sync"
77
"testing"
88
"time"
@@ -122,7 +122,7 @@ func TestReceiveFrom(t *testing.T) {
122122
pm := &fakePeerManager{}
123123
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")
124124

125-
p := peer.ID(fmt.Sprint(123))
125+
p := peer.ID(strconv.Itoa(123))
126126
block := blocks.NewBlock([]byte("block"))
127127

128128
firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
@@ -169,7 +169,7 @@ func TestReceiveBlocksWhenManagerShutdown(t *testing.T) {
169169
pm := &fakePeerManager{}
170170
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")
171171

172-
p := peer.ID(fmt.Sprint(123))
172+
p := peer.ID(strconv.Itoa(123))
173173
block := blocks.NewBlock([]byte("block"))
174174

175175
firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
@@ -203,7 +203,7 @@ func TestReceiveBlocksWhenSessionContextCancelled(t *testing.T) {
203203
pm := &fakePeerManager{}
204204
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")
205205

206-
p := peer.ID(fmt.Sprint(123))
206+
p := peer.ID(strconv.Itoa(123))
207207
block := blocks.NewBlock([]byte("block"))
208208

209209
firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)
@@ -239,7 +239,7 @@ func TestShutdown(t *testing.T) {
239239
pm := &fakePeerManager{}
240240
sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "")
241241

242-
p := peer.ID(fmt.Sprint(123))
242+
p := peer.ID(strconv.Itoa(123))
243243
block := blocks.NewBlock([]byte("block"))
244244
cids := []cid.Cid{block.Cid()}
245245
firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession)

bitswap/client/internal/tracing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package internal
22

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

76
"go.opentelemetry.io/otel"
87
"go.opentelemetry.io/otel/trace"
98
)
109

1110
func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
12-
return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...)
11+
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
1312
}

bitswap/internal/testutil/testutil.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package testutil
22

33
import (
44
"crypto/rand"
5-
"fmt"
5+
"strconv"
66

77
"github.com/ipfs/boxo/bitswap/client/wantlist"
88
bsmsg "github.com/ipfs/boxo/bitswap/message"
@@ -62,7 +62,7 @@ func GeneratePeers(n int) []peer.ID {
6262
peerIds := make([]peer.ID, 0, n)
6363
for i := 0; i < n; i++ {
6464
peerSeq++
65-
p := peer.ID(fmt.Sprint(peerSeq))
65+
p := peer.ID(strconv.Itoa(peerSeq))
6666
peerIds = append(peerIds, p)
6767
}
6868
return peerIds

bitswap/internal/tracing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package internal
22

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

76
"go.opentelemetry.io/otel"
87
"go.opentelemetry.io/otel/trace"
98
)
109

1110
func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
12-
return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...)
11+
return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...)
1312
}

bitswap/network/ipfs_impl_test.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78
"testing"
@@ -69,7 +70,7 @@ func (r *receiver) PeerDisconnected(p peer.ID) {
6970
r.connectionEvent <- false
7071
}
7172

72-
var errMockNetErr = fmt.Errorf("network err")
73+
var errMockNetErr = errors.New("network err")
7374

7475
type ErrStream struct {
7576
network.Stream

bitswap/server/internal/decision/blockstoremanager.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package decision
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"sync"
77

88
bstore "github.com/ipfs/boxo/blockstore"
@@ -77,7 +77,7 @@ func (bsm *blockstoreManager) addJob(ctx context.Context, job func()) error {
7777
case <-ctx.Done():
7878
return ctx.Err()
7979
case <-bsm.stopChan:
80-
return fmt.Errorf("shutting down")
80+
return errors.New("shutting down")
8181
case bsm.jobs <- job:
8282
bsm.pendingGauge.Inc()
8383
return nil

bitswap/server/internal/decision/engine_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/binary"
88
"errors"
99
"fmt"
10+
"strconv"
1011
"strings"
1112
"sync"
1213
"testing"
@@ -1647,7 +1648,7 @@ func TestWantlistGrowsToLimit(t *testing.T) {
16471648
// Send in two messages to test reslicing.
16481649
m := message.New(false)
16491650
for j := limit; j != 0; j-- {
1650-
m.AddEntry(blocks.NewBlock([]byte(fmt.Sprint(j))).Cid(), 0, pb.Message_Wantlist_Block, true)
1651+
m.AddEntry(blocks.NewBlock([]byte(strconv.Itoa(j))).Cid(), 0, pb.Message_Wantlist_Block, true)
16511652
}
16521653
warsaw.Engine.MessageReceived(ctx, riga.Peer, m)
16531654

blockservice/internal/tracing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package internal
22

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

76
"go.opentelemetry.io/otel"
87
"go.opentelemetry.io/otel/trace"
98
)
109

1110
func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
12-
return otel.Tracer("go-blockservice").Start(ctx, fmt.Sprintf("Blockservice.%s", name), opts...)
11+
return otel.Tracer("go-blockservice").Start(ctx, "Blockservice."+name, opts...)
1312
}

files/serialfile_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package files
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"os"
@@ -125,22 +126,22 @@ testInputs:
125126
// root node.
126127
if path == "" {
127128
if rootFound {
128-
return fmt.Errorf("found root twice")
129+
return errors.New("found root twice")
129130
}
130131
if sf != nd {
131-
return fmt.Errorf("wrong root")
132+
return errors.New("wrong root")
132133
}
133134
rootFound = true
134135
return nil
135136
}
136137
actualPaths = append(actualPaths, path)
137138
if !hidden && isFullPathHidden(path) {
138-
return fmt.Errorf("found a hidden file")
139+
return errors.New("found a hidden file")
139140
}
140141
components := filepath.SplitList(path)
141142
for i := range components {
142143
if fileFilter.Rules.MatchesPath(filepath.Join(components[:i+1]...)) {
143-
return fmt.Errorf("found a file that should be excluded")
144+
return errors.New("found a file that should be excluded")
144145
}
145146
}
146147

@@ -152,7 +153,7 @@ testInputs:
152153

153154
switch nd := nd.(type) {
154155
case *Symlink:
155-
return fmt.Errorf("didn't expect a symlink")
156+
return errors.New("didn't expect a symlink")
156157
case Directory:
157158
if data != "" {
158159
return fmt.Errorf("expected a directory at %q", path)

gateway/assets/node.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package assets
33
import (
44
"encoding/hex"
55
"fmt"
6+
"strconv"
67

78
"github.com/ipld/go-ipld-prime/datamodel"
89
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
@@ -55,21 +56,21 @@ func ParseNode(node datamodel.Node) (*ParsedNode, error) {
5556
return nil, err
5657
}
5758

58-
dag.Keys = append(dag.Keys, &ParsedNode{Value: fmt.Sprintf("%d", k)})
59+
dag.Keys = append(dag.Keys, &ParsedNode{Value: strconv.FormatInt(k, 10)})
5960
dag.Values = append(dag.Values, vd)
6061
}
6162
case datamodel.Kind_Bool:
6263
v, err := node.AsBool()
6364
if err != nil {
6465
return nil, err
6566
}
66-
dag.Value = fmt.Sprintf("%t", v)
67+
dag.Value = strconv.FormatBool(v)
6768
case datamodel.Kind_Int:
6869
v, err := node.AsInt()
6970
if err != nil {
7071
return nil, err
7172
}
72-
dag.Value = fmt.Sprintf("%d", v)
73+
dag.Value = strconv.FormatInt(v, 10)
7374
case datamodel.Kind_Float:
7475
v, err := node.AsFloat()
7576
if err != nil {

gateway/blocks_backend.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (bb *BlocksBackend) Get(ctx context.Context, path path.ImmutablePath, range
205205
return ContentPathMetadata{}, nil, fmt.Errorf("could not get cumulative directory DAG size: %w", err)
206206
}
207207
if sz < 0 {
208-
return ContentPathMetadata{}, nil, fmt.Errorf("directory cumulative DAG size cannot be negative")
208+
return ContentPathMetadata{}, nil, errors.New("directory cumulative DAG size cannot be negative")
209209
}
210210
return md, NewGetResponseFromDirectoryListing(uint64(sz), dir.EnumLinksAsync(ctx), nil), nil
211211
}
@@ -287,7 +287,7 @@ func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (Con
287287
return md, NewHeadResponseForFile(f, sz), nil
288288
}
289289

290-
return ContentPathMetadata{}, nil, fmt.Errorf("unsupported UnixFS file type")
290+
return ContentPathMetadata{}, nil, errors.New("unsupported UnixFS file type")
291291
}
292292

293293
// emptyRoot is a CAR root with the empty identity CID. CAR files are recommended
@@ -335,7 +335,7 @@ func (bb *BlocksBackend) GetCAR(ctx context.Context, p path.ImmutablePath, param
335335
}
336336

337337
if p.Namespace() != path.IPFSNamespace {
338-
return ContentPathMetadata{}, nil, fmt.Errorf("path does not have /ipfs/ prefix")
338+
return ContentPathMetadata{}, nil, errors.New("path does not have /ipfs/ prefix")
339339
}
340340

341341
r, w := io.Pipe()
@@ -482,7 +482,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
482482

483483
fnd, ok := nd.(datamodel.LargeBytesNode)
484484
if !ok {
485-
return fmt.Errorf("could not process file since it did not present as large bytes")
485+
return errors.New("could not process file since it did not present as large bytes")
486486
}
487487
f, err := fnd.AsLargeBytes()
488488
if err != nil {
@@ -532,7 +532,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
532532

533533
numToRead := 1 + to - from
534534
if numToRead < 0 {
535-
return fmt.Errorf("tried to read less than zero bytes")
535+
return errors.New("tried to read less than zero bytes")
536536
}
537537

538538
if _, err := f.Seek(from, io.SeekStart); err != nil {

gateway/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (e *ErrorRetryAfter) Error() string {
5252
text = e.Err.Error()
5353
}
5454
if e.RetryAfter != 0 {
55-
text += fmt.Sprintf(", retry after %s", e.humanizedRoundSeconds())
55+
text += ", retry after " + e.humanizedRoundSeconds()
5656
}
5757
return text
5858
}

0 commit comments

Comments
 (0)