diff --git a/bitswap/bitswap_test.go b/bitswap/bitswap_test.go index 014f75a07..505871d6e 100644 --- a/bitswap/bitswap_test.go +++ b/bitswap/bitswap_test.go @@ -3,6 +3,7 @@ package bitswap_test import ( "bytes" "context" + "errors" "fmt" "os" "sync" @@ -432,10 +433,10 @@ func TestBasicBitswap(t *testing.T) { // peer should no longer keep second peer's want if err = tu.WaitFor(ctx, func() error { if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 { - return fmt.Errorf("should have no items in other peers wantlist") + return errors.New("should have no items in other peers wantlist") } if len(instances[1].Exchange.GetWantlist()) != 0 { - return fmt.Errorf("shouldnt have anything in wantlist") + return errors.New("shouldnt have anything in wantlist") } return nil }); err != nil { diff --git a/bitswap/client/bitswap_with_sessions_test.go b/bitswap/client/bitswap_with_sessions_test.go index 54c320236..0baede658 100644 --- a/bitswap/client/bitswap_with_sessions_test.go +++ b/bitswap/client/bitswap_with_sessions_test.go @@ -2,6 +2,7 @@ package client_test import ( "context" + "errors" "fmt" "testing" "time" @@ -489,7 +490,7 @@ func TestWantlistClearsOnCancel(t *testing.T) { if err := tu.WaitFor(ctx, func() error { if len(a.Exchange.GetWantlist()) > 0 { - return fmt.Errorf("expected empty wantlist") + return errors.New("expected empty wantlist") } return nil }); err != nil { diff --git a/bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go b/bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go index ee90ddde9..038213c25 100644 --- a/bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go +++ b/bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go @@ -2,7 +2,7 @@ package messagequeue import ( "context" - "fmt" + "errors" "sync" "testing" "time" @@ -342,7 +342,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) { tr := timeoutRecorder{} clock := clock.NewMock() pinged := make(chan struct{}) - pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: fmt.Errorf("ping error")} + pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged, err: errors.New("ping error")} timeoutsTriggered := make(chan struct{}) dhtm := newDontHaveTimeoutMgrWithParams(pc, tr.onTimeout, diff --git a/bitswap/client/internal/messagequeue/messagequeue_test.go b/bitswap/client/internal/messagequeue/messagequeue_test.go index 9abfa68b0..4d361c5d5 100644 --- a/bitswap/client/internal/messagequeue/messagequeue_test.go +++ b/bitswap/client/internal/messagequeue/messagequeue_test.go @@ -2,7 +2,7 @@ package messagequeue import ( "context" - "fmt" + "errors" "math" "math/rand" "sync" @@ -40,7 +40,7 @@ func (fmn *fakeMessageNetwork) NewMessageSender(context.Context, peer.ID, *bsnet func (fms *fakeMessageNetwork) Self() peer.ID { return "" } func (fms *fakeMessageNetwork) Latency(peer.ID) time.Duration { return 0 } func (fms *fakeMessageNetwork) Ping(context.Context, peer.ID) ping.Result { - return ping.Result{Error: fmt.Errorf("ping error")} + return ping.Result{Error: errors.New("ping error")} } type fakeDontHaveTimeoutMgr struct { diff --git a/bitswap/client/internal/providerquerymanager/providerquerymanager.go b/bitswap/client/internal/providerquerymanager/providerquerymanager.go index 09bfc5b4e..f918c409a 100644 --- a/bitswap/client/internal/providerquerymanager/providerquerymanager.go +++ b/bitswap/client/internal/providerquerymanager/providerquerymanager.go @@ -355,7 +355,7 @@ func (rpm *receivedProviderMessage) handle(pqm *ProviderQueryManager) { } func (fpqm *finishedProviderQueryMessage) debugMessage() string { - return fmt.Sprintf("Finished Provider Query on cid: %s", fpqm.k.String()) + return "Finished Provider Query on cid: " + fpqm.k.String() } func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) { @@ -372,7 +372,7 @@ func (fpqm *finishedProviderQueryMessage) handle(pqm *ProviderQueryManager) { } func (npqm *newProvideQueryMessage) debugMessage() string { - return fmt.Sprintf("New Provider Query on cid: %s", npqm.k.String()) + return "New Provider Query on cid: " + npqm.k.String() } func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) { @@ -407,7 +407,7 @@ func (npqm *newProvideQueryMessage) handle(pqm *ProviderQueryManager) { } func (crm *cancelRequestMessage) debugMessage() string { - return fmt.Sprintf("Cancel provider query on cid: %s", crm.k.String()) + return "Cancel provider query on cid: " + crm.k.String() } func (crm *cancelRequestMessage) handle(pqm *ProviderQueryManager) { diff --git a/bitswap/client/internal/sessionmanager/sessionmanager_test.go b/bitswap/client/internal/sessionmanager/sessionmanager_test.go index 86f7f8df5..71cd45601 100644 --- a/bitswap/client/internal/sessionmanager/sessionmanager_test.go +++ b/bitswap/client/internal/sessionmanager/sessionmanager_test.go @@ -2,7 +2,8 @@ package sessionmanager import ( "context" - "fmt" + + "strconv" "sync" "testing" "time" @@ -122,7 +123,7 @@ func TestReceiveFrom(t *testing.T) { pm := &fakePeerManager{} sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "") - p := peer.ID(fmt.Sprint(123)) + p := peer.ID(strconv.Itoa(123)) block := blocks.NewBlock([]byte("block")) firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession) @@ -169,7 +170,7 @@ func TestReceiveBlocksWhenManagerShutdown(t *testing.T) { pm := &fakePeerManager{} sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "") - p := peer.ID(fmt.Sprint(123)) + p := peer.ID(strconv.Itoa(123)) block := blocks.NewBlock([]byte("block")) firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession) @@ -203,7 +204,7 @@ func TestReceiveBlocksWhenSessionContextCancelled(t *testing.T) { pm := &fakePeerManager{} sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "") - p := peer.ID(fmt.Sprint(123)) + p := peer.ID(strconv.Itoa(123)) block := blocks.NewBlock([]byte("block")) firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession) @@ -239,7 +240,7 @@ func TestShutdown(t *testing.T) { pm := &fakePeerManager{} sm := New(ctx, sessionFactory, sim, peerManagerFactory, bpm, pm, notif, "") - p := peer.ID(fmt.Sprint(123)) + p := peer.ID(strconv.Itoa(123)) block := blocks.NewBlock([]byte("block")) cids := []cid.Cid{block.Cid()} firstSession := sm.NewSession(ctx, time.Second, delay.Fixed(time.Minute)).(*fakeSession) diff --git a/bitswap/client/internal/tracing.go b/bitswap/client/internal/tracing.go index aa1f7992f..aac2544d2 100644 --- a/bitswap/client/internal/tracing.go +++ b/bitswap/client/internal/tracing.go @@ -2,12 +2,11 @@ package internal import ( "context" - "fmt" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" ) func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { - return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...) + return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...) } diff --git a/bitswap/internal/testutil/testutil.go b/bitswap/internal/testutil/testutil.go index eb633bfc3..6ea0ce4cb 100644 --- a/bitswap/internal/testutil/testutil.go +++ b/bitswap/internal/testutil/testutil.go @@ -2,7 +2,8 @@ package testutil import ( "crypto/rand" - "fmt" + + "strconv" "github.com/ipfs/boxo/bitswap/client/wantlist" bsmsg "github.com/ipfs/boxo/bitswap/message" @@ -62,7 +63,7 @@ func GeneratePeers(n int) []peer.ID { peerIds := make([]peer.ID, 0, n) for i := 0; i < n; i++ { peerSeq++ - p := peer.ID(fmt.Sprint(peerSeq)) + p := peer.ID(strconv.Itoa(peerSeq)) peerIds = append(peerIds, p) } return peerIds diff --git a/bitswap/internal/tracing.go b/bitswap/internal/tracing.go index aa1f7992f..aac2544d2 100644 --- a/bitswap/internal/tracing.go +++ b/bitswap/internal/tracing.go @@ -2,12 +2,11 @@ package internal import ( "context" - "fmt" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" ) func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { - return otel.Tracer("go-bitswap").Start(ctx, fmt.Sprintf("Bitswap.%s", name), opts...) + return otel.Tracer("go-bitswap").Start(ctx, "Bitswap."+name, opts...) } diff --git a/bitswap/network/ipfs_impl_test.go b/bitswap/network/ipfs_impl_test.go index 196fc7d55..af76e20d6 100644 --- a/bitswap/network/ipfs_impl_test.go +++ b/bitswap/network/ipfs_impl_test.go @@ -2,6 +2,7 @@ package network_test import ( "context" + "errors" "fmt" "sync" "testing" @@ -69,7 +70,7 @@ func (r *receiver) PeerDisconnected(p peer.ID) { r.connectionEvent <- false } -var errMockNetErr = fmt.Errorf("network err") +var errMockNetErr = errors.New("network err") type ErrStream struct { network.Stream diff --git a/bitswap/server/internal/decision/blockstoremanager.go b/bitswap/server/internal/decision/blockstoremanager.go index fe438b4d9..ea7fb100e 100644 --- a/bitswap/server/internal/decision/blockstoremanager.go +++ b/bitswap/server/internal/decision/blockstoremanager.go @@ -2,7 +2,8 @@ package decision import ( "context" - "fmt" + + "errors" "sync" bstore "github.com/ipfs/boxo/blockstore" @@ -77,7 +78,7 @@ func (bsm *blockstoreManager) addJob(ctx context.Context, job func()) error { case <-ctx.Done(): return ctx.Err() case <-bsm.stopChan: - return fmt.Errorf("shutting down") + return errors.New("shutting down") case bsm.jobs <- job: bsm.pendingGauge.Inc() return nil diff --git a/bitswap/server/internal/decision/engine_test.go b/bitswap/server/internal/decision/engine_test.go index b7382f817..c25e3508d 100644 --- a/bitswap/server/internal/decision/engine_test.go +++ b/bitswap/server/internal/decision/engine_test.go @@ -7,6 +7,7 @@ import ( "encoding/binary" "errors" "fmt" + "strconv" "strings" "sync" "testing" @@ -1647,7 +1648,7 @@ func TestWantlistGrowsToLimit(t *testing.T) { // Send in two messages to test reslicing. m := message.New(false) for j := limit; j != 0; j-- { - m.AddEntry(blocks.NewBlock([]byte(fmt.Sprint(j))).Cid(), 0, pb.Message_Wantlist_Block, true) + m.AddEntry(blocks.NewBlock([]byte(strconv.Itoa(j))).Cid(), 0, pb.Message_Wantlist_Block, true) } warsaw.Engine.MessageReceived(ctx, riga.Peer, m) diff --git a/blockservice/internal/tracing.go b/blockservice/internal/tracing.go index 96a61ff42..44ffbfccc 100644 --- a/blockservice/internal/tracing.go +++ b/blockservice/internal/tracing.go @@ -2,12 +2,11 @@ package internal import ( "context" - "fmt" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" ) func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { - return otel.Tracer("go-blockservice").Start(ctx, fmt.Sprintf("Blockservice.%s", name), opts...) + return otel.Tracer("go-blockservice").Start(ctx, "Blockservice."+name, opts...) } diff --git a/files/serialfile_test.go b/files/serialfile_test.go index 2d480a1df..2f08bada0 100644 --- a/files/serialfile_test.go +++ b/files/serialfile_test.go @@ -1,6 +1,7 @@ package files import ( + "errors" "fmt" "io" "os" @@ -125,22 +126,22 @@ testInputs: // root node. if path == "" { if rootFound { - return fmt.Errorf("found root twice") + return errors.New("found root twice") } if sf != nd { - return fmt.Errorf("wrong root") + return errors.New("wrong root") } rootFound = true return nil } actualPaths = append(actualPaths, path) if !hidden && isFullPathHidden(path) { - return fmt.Errorf("found a hidden file") + return errors.New("found a hidden file") } components := filepath.SplitList(path) for i := range components { if fileFilter.Rules.MatchesPath(filepath.Join(components[:i+1]...)) { - return fmt.Errorf("found a file that should be excluded") + return errors.New("found a file that should be excluded") } } @@ -152,7 +153,7 @@ testInputs: switch nd := nd.(type) { case *Symlink: - return fmt.Errorf("didn't expect a symlink") + return errors.New("didn't expect a symlink") case Directory: if data != "" { return fmt.Errorf("expected a directory at %q", path) diff --git a/gateway/assets/node.go b/gateway/assets/node.go index 695bb8470..7e6a645a4 100644 --- a/gateway/assets/node.go +++ b/gateway/assets/node.go @@ -3,6 +3,7 @@ package assets import ( "encoding/hex" "fmt" + "strconv" "github.com/ipld/go-ipld-prime/datamodel" cidlink "github.com/ipld/go-ipld-prime/linking/cid" @@ -55,7 +56,7 @@ func ParseNode(node datamodel.Node) (*ParsedNode, error) { return nil, err } - dag.Keys = append(dag.Keys, &ParsedNode{Value: fmt.Sprintf("%d", k)}) + dag.Keys = append(dag.Keys, &ParsedNode{Value: strconv.FormatInt(k, 10)}) dag.Values = append(dag.Values, vd) } case datamodel.Kind_Bool: @@ -63,13 +64,13 @@ func ParseNode(node datamodel.Node) (*ParsedNode, error) { if err != nil { return nil, err } - dag.Value = fmt.Sprintf("%t", v) + dag.Value = strconv.FormatBool(v) case datamodel.Kind_Int: v, err := node.AsInt() if err != nil { return nil, err } - dag.Value = fmt.Sprintf("%d", v) + dag.Value = strconv.FormatInt(v, 10) case datamodel.Kind_Float: v, err := node.AsFloat() if err != nil { diff --git a/gateway/blocks_backend.go b/gateway/blocks_backend.go index a87b05c6b..4faadb206 100644 --- a/gateway/blocks_backend.go +++ b/gateway/blocks_backend.go @@ -205,7 +205,7 @@ func (bb *BlocksBackend) Get(ctx context.Context, path path.ImmutablePath, range return ContentPathMetadata{}, nil, fmt.Errorf("could not get cumulative directory DAG size: %w", err) } if sz < 0 { - return ContentPathMetadata{}, nil, fmt.Errorf("directory cumulative DAG size cannot be negative") + return ContentPathMetadata{}, nil, errors.New("directory cumulative DAG size cannot be negative") } return md, NewGetResponseFromDirectoryListing(uint64(sz), dir.EnumLinksAsync(ctx), nil), nil } @@ -287,7 +287,7 @@ func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (Con return md, NewHeadResponseForFile(f, sz), nil } - return ContentPathMetadata{}, nil, fmt.Errorf("unsupported UnixFS file type") + return ContentPathMetadata{}, nil, errors.New("unsupported UnixFS file type") } // 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 } if p.Namespace() != path.IPFSNamespace { - return ContentPathMetadata{}, nil, fmt.Errorf("path does not have /ipfs/ prefix") + return ContentPathMetadata{}, nil, errors.New("path does not have /ipfs/ prefix") } r, w := io.Pipe() @@ -482,7 +482,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params fnd, ok := nd.(datamodel.LargeBytesNode) if !ok { - return fmt.Errorf("could not process file since it did not present as large bytes") + return errors.New("could not process file since it did not present as large bytes") } f, err := fnd.AsLargeBytes() if err != nil { @@ -532,7 +532,7 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params numToRead := 1 + to - from if numToRead < 0 { - return fmt.Errorf("tried to read less than zero bytes") + return errors.New("tried to read less than zero bytes") } if _, err := f.Seek(from, io.SeekStart); err != nil { diff --git a/gateway/errors.go b/gateway/errors.go index 4e4bb6823..79cedcee0 100644 --- a/gateway/errors.go +++ b/gateway/errors.go @@ -52,7 +52,7 @@ func (e *ErrorRetryAfter) Error() string { text = e.Err.Error() } if e.RetryAfter != 0 { - text += fmt.Sprintf(", retry after %s", e.humanizedRoundSeconds()) + text += ", retry after " + e.humanizedRoundSeconds() } return text } diff --git a/gateway/gateway.go b/gateway/gateway.go index 28cf5d295..b2edbf20c 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -2,6 +2,7 @@ package gateway import ( "context" + "errors" "fmt" "io" "net/http" @@ -120,7 +121,7 @@ type DagByteRange struct { func NewDagByteRange(rangeStr string) (DagByteRange, error) { rangeElems := strings.Split(rangeStr, ":") if len(rangeElems) != 2 { - return DagByteRange{}, fmt.Errorf("range must have two numbers separated with ':'") + return DagByteRange{}, errors.New("range must have two numbers separated with ':'") } from, err := strconv.ParseInt(rangeElems[0], 10, 64) if err != nil { @@ -140,11 +141,11 @@ func NewDagByteRange(rangeStr string) (DagByteRange, error) { } if from >= 0 && to >= 0 && from > to { - return DagByteRange{}, fmt.Errorf("cannot have an entity-bytes range where 'from' is after 'to'") + return DagByteRange{}, errors.New("cannot have an entity-bytes range where 'from' is after 'to'") } if from < 0 && to < 0 && from > to { - return DagByteRange{}, fmt.Errorf("cannot have an entity-bytes range where 'from' is after 'to'") + return DagByteRange{}, errors.New("cannot have an entity-bytes range where 'from' is after 'to'") } return DagByteRange{ diff --git a/gateway/handler.go b/gateway/handler.go index 29a816b7a..1299c7e59 100644 --- a/gateway/handler.go +++ b/gateway/handler.go @@ -830,7 +830,7 @@ func (i *handler) handleServiceWorkerRegistration(w http.ResponseWriter, r *http if r.Header.Get("Service-Worker") == "script" { matched, _ := regexp.MatchString(`^/ip[fn]s/[^/]+$`, r.URL.Path) if matched { - err := fmt.Errorf("navigator.serviceWorker: registration is not allowed for this scope") + err := errors.New("navigator.serviceWorker: registration is not allowed for this scope") i.webError(w, r, err, http.StatusBadRequest) return true } diff --git a/gateway/handler_car.go b/gateway/handler_car.go index 21b90108c..e42c0fde2 100644 --- a/gateway/handler_car.go +++ b/gateway/handler_car.go @@ -3,6 +3,7 @@ package gateway import ( "context" "encoding/binary" + "errors" "fmt" "io" "net/http" @@ -148,7 +149,7 @@ func buildCarParams(r *http.Request, contentTypeParams map[string]string) (CarPa case "": // noop, client does not care about version case "1": // noop, we support this default: - return CarParams{}, fmt.Errorf("unsupported application/vnd.ipld.car version: only version=1 is supported") + return CarParams{}, errors.New("unsupported application/vnd.ipld.car version: only version=1 is supported") } // optional order from IPIP-412 @@ -206,7 +207,7 @@ func buildContentTypeFromCarParams(params CarParams) string { func getCarRootCidAndLastSegment(imPath path.ImmutablePath) (cid.Cid, string, error) { imPathStr := imPath.String() if !strings.HasPrefix(imPathStr, "/ipfs/") { - return cid.Undef, "", fmt.Errorf("path does not have /ipfs/ prefix") + return cid.Undef, "", errors.New("path does not have /ipfs/ prefix") } firstSegment, remainingSegments, _ := strings.Cut(imPathStr[6:], "/") diff --git a/gateway/handler_defaults.go b/gateway/handler_defaults.go index 648d51328..78e5af952 100644 --- a/gateway/handler_defaults.go +++ b/gateway/handler_defaults.go @@ -88,7 +88,7 @@ func (i *handler) serveDefaults(ctx context.Context, w http.ResponseWriter, r *h defer getResp.Close() default: // This shouldn't be possible to reach which is why it is a 500 rather than 4XX error - i.webError(w, r, fmt.Errorf("invalid method: cannot use this HTTP method with the given request"), http.StatusInternalServerError) + i.webError(w, r, errors.New("invalid method: cannot use this HTTP method with the given request"), http.StatusInternalServerError) return false } @@ -107,7 +107,7 @@ func (i *handler) serveDefaults(ctx context.Context, w http.ResponseWriter, r *h blockSize = getResp.bytesSize dataAsReadSeekCloser, ok := getResp.bytes.(io.ReadSeekCloser) if !ok { - i.webError(w, r, fmt.Errorf("expected returned non-UnixFS data to be seekable"), http.StatusInternalServerError) + i.webError(w, r, errors.New("expected returned non-UnixFS data to be seekable"), http.StatusInternalServerError) } dataToRender = dataAsReadSeekCloser } @@ -151,7 +151,7 @@ func (i *handler) serveDefaults(ctx context.Context, w http.ResponseWriter, r *h } } - i.webError(w, r, fmt.Errorf("unsupported UnixFS type"), http.StatusInternalServerError) + i.webError(w, r, errors.New("unsupported UnixFS type"), http.StatusInternalServerError) return false } } diff --git a/gateway/handler_unixfs__redirects.go b/gateway/handler_unixfs__redirects.go index a6fe24826..7527ca891 100644 --- a/gateway/handler_unixfs__redirects.go +++ b/gateway/handler_unixfs__redirects.go @@ -1,6 +1,7 @@ package gateway import ( + "errors" "fmt" "io" "net/http" @@ -187,7 +188,7 @@ func (i *handler) getRedirectRules(r *http.Request, redirectsPath path.Immutable defer redirectsFileGetResp.Close() if redirectsFileGetResp.bytes == nil { - return false, nil, fmt.Errorf(" _redirects is not a file") + return false, nil, errors.New(" _redirects is not a file") } f := redirectsFileGetResp.bytes diff --git a/gateway/handler_unixfs_file.go b/gateway/handler_unixfs_file.go index 734e11025..6402515f0 100644 --- a/gateway/handler_unixfs_file.go +++ b/gateway/handler_unixfs_file.go @@ -3,7 +3,7 @@ package gateway import ( "bytes" "context" - "fmt" + "io" "mime" "net/http" @@ -63,7 +63,7 @@ func (i *handler) serveFile(ctx context.Context, w http.ResponseWriter, r *http. mimeType, err := mimetype.DetectReader(tr) if err != nil { - http.Error(w, fmt.Sprintf("cannot detect content-type: %s", err.Error()), http.StatusInternalServerError) + http.Error(w, "cannot detect content-type: "+err.Error(), http.StatusInternalServerError) return false } diff --git a/gateway/lazyseek.go b/gateway/lazyseek.go index 0f4920fad..e0ec44a82 100644 --- a/gateway/lazyseek.go +++ b/gateway/lazyseek.go @@ -1,6 +1,7 @@ package gateway import ( + "errors" "fmt" "io" ) @@ -23,7 +24,7 @@ func (s *lazySeeker) Seek(offset int64, whence int) (int64, error) { return s.Seek(s.offset+offset, io.SeekStart) case io.SeekStart: if offset < 0 { - return s.offset, fmt.Errorf("invalid seek offset") + return s.offset, errors.New("invalid seek offset") } s.offset = offset return s.offset, nil diff --git a/gateway/lazyseek_test.go b/gateway/lazyseek_test.go index b3ed4e4e2..fdc6d2b34 100644 --- a/gateway/lazyseek_test.go +++ b/gateway/lazyseek_test.go @@ -1,7 +1,7 @@ package gateway import ( - "fmt" + "errors" "io" "strings" "testing" @@ -13,7 +13,7 @@ type badSeeker struct { io.ReadSeeker } -var errBadSeek = fmt.Errorf("bad seeker") +var errBadSeek = errors.New("bad seeker") func (bs badSeeker) Seek(offset int64, whence int) (int64, error) { off, err := bs.ReadSeeker.Seek(0, io.SeekCurrent) diff --git a/gateway/metrics.go b/gateway/metrics.go index df8639956..035686e45 100644 --- a/gateway/metrics.go +++ b/gateway/metrics.go @@ -2,7 +2,7 @@ package gateway import ( "context" - "fmt" + "io" "time" @@ -298,5 +298,5 @@ func newHistogramMetric(name string, help string) *prometheus.HistogramVec { var tracer = otel.Tracer("boxo/gateway") func spanTrace(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { - return tracer.Start(ctx, fmt.Sprintf("Gateway.%s", spanName), opts...) + return tracer.Start(ctx, "Gateway."+spanName, opts...) } diff --git a/ipld/merkledag/coding.go b/ipld/merkledag/coding.go index ad9440404..a455a6a44 100644 --- a/ipld/merkledag/coding.go +++ b/ipld/merkledag/coding.go @@ -1,6 +1,7 @@ package merkledag import ( + "errors" "fmt" "sort" "strings" @@ -199,7 +200,7 @@ func DecodeProtobuf(encoded []byte) (*ProtoNode, error) { func DecodeProtobufBlock(b blocks.Block) (format.Node, error) { c := b.Cid() if c.Type() != cid.DagProtobuf { - return nil, fmt.Errorf("this function can only decode protobuf nodes") + return nil, errors.New("this function can only decode protobuf nodes") } decnd, err := DecodeProtobuf(b.RawData()) diff --git a/ipld/merkledag/coding_test.go b/ipld/merkledag/coding_test.go index a213a912c..33953cf5b 100644 --- a/ipld/merkledag/coding_test.go +++ b/ipld/merkledag/coding_test.go @@ -2,7 +2,8 @@ package merkledag_test import ( "bytes" - "fmt" + + "strconv" "testing" "github.com/ipfs/boxo/ipld/merkledag" @@ -20,7 +21,7 @@ func init() { node := &merkledag.ProtoNode{} node.SetData(someData) for i := 0; i < 10; i++ { - node.AddRawLink(fmt.Sprintf("%d", i), &ipld.Link{ + node.AddRawLink(strconv.Itoa(i), &ipld.Link{ Size: 10, Cid: someCid, }) diff --git a/ipld/merkledag/dagutils/diffenum_test.go b/ipld/merkledag/dagutils/diffenum_test.go index 41fbfc669..d22ea7288 100644 --- a/ipld/merkledag/dagutils/diffenum_test.go +++ b/ipld/merkledag/dagutils/diffenum_test.go @@ -2,6 +2,7 @@ package dagutils import ( "context" + "errors" "fmt" "testing" @@ -111,7 +112,7 @@ func TestNameMatching(t *testing.T) { diff := getLinkDiff(nds["a1"], nds["a2"]) if len(diff) != 1 { - t.Fatal(fmt.Errorf("node diff didn't match by name")) + t.Fatal(errors.New("node diff didn't match by name")) } } @@ -120,10 +121,10 @@ func TestNameMatching2(t *testing.T) { diff := getLinkDiff(nds["a1"], nds["a2"]) if len(diff) != 2 { - t.Fatal(fmt.Errorf("incorrect number of link diff elements")) + t.Fatal(errors.New("incorrect number of link diff elements")) } if !(diff[0].bef.Equals(nds["a1"].Links()[0].Cid) && diff[0].aft.Equals(nds["a2"].Links()[0].Cid)) { - t.Fatal(fmt.Errorf("node diff didn't match by name")) + t.Fatal(errors.New("node diff didn't match by name")) } } @@ -185,7 +186,7 @@ func (gl *getLogger) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.N func assertCidList(a, b []cid.Cid) error { if len(a) != len(b) { - return fmt.Errorf("got different number of cids than expected") + return errors.New("got different number of cids than expected") } for i, c := range a { if !c.Equals(b[i]) { diff --git a/ipld/merkledag/merkledag.go b/ipld/merkledag/merkledag.go index 7d830ad2e..d695a65f4 100644 --- a/ipld/merkledag/merkledag.go +++ b/ipld/merkledag/merkledag.go @@ -3,7 +3,8 @@ package merkledag import ( "context" - "fmt" + + "errors" "sync" bserv "github.com/ipfs/boxo/blockservice" @@ -56,7 +57,7 @@ type dagService struct { // Add adds a node to the dagService, storing the block in the BlockService func (n *dagService) Add(ctx context.Context, nd format.Node) error { if n == nil { // FIXME remove this assertion. protect with constructor invariant - return fmt.Errorf("dagService is nil") + return errors.New("dagService is nil") } return n.Blocks.AddBlock(ctx, nd) @@ -73,7 +74,7 @@ func (n *dagService) AddMany(ctx context.Context, nds []format.Node) error { // Get retrieves a node from the dagService, fetching the block in the BlockService func (n *dagService) Get(ctx context.Context, c cid.Cid) (format.Node, error) { if n == nil { - return nil, fmt.Errorf("dagService is nil") + return nil, errors.New("dagService is nil") } ctx, cancel := context.WithCancel(ctx) @@ -254,7 +255,7 @@ func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []cid.Cid, d case b, ok := <-blocks: if !ok { if count != len(keys) { - out <- &format.NodeOption{Err: fmt.Errorf("failed to fetch all nodes")} + out <- &format.NodeOption{Err: errors.New("failed to fetch all nodes")} } return } diff --git a/ipld/merkledag/merkledag_test.go b/ipld/merkledag/merkledag_test.go index 785159aff..ffe4946ca 100644 --- a/ipld/merkledag/merkledag_test.go +++ b/ipld/merkledag/merkledag_test.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "math" + "strconv" "strings" "sync" "testing" @@ -1220,7 +1221,7 @@ func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode { for i := 0; i < width; i++ { c := getChild() - if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil { + if err := cur.AddNodeLink(strconv.Itoa(i), c); err != nil { panic(err) } } diff --git a/ipld/merkledag/node.go b/ipld/merkledag/node.go index 70acbc73e..782d7c4ef 100644 --- a/ipld/merkledag/node.go +++ b/ipld/merkledag/node.go @@ -21,9 +21,9 @@ import ( // Common errors var ( - ErrNotProtobuf = fmt.Errorf("expected protobuf dag node") - ErrNotRawNode = fmt.Errorf("expected raw bytes node") - ErrLinkNotFound = fmt.Errorf("no link by that name") + ErrNotProtobuf = errors.New("expected protobuf dag node") + ErrNotRawNode = errors.New("expected raw bytes node") + ErrLinkNotFound = errors.New("no link by that name") ) var log = logging.Logger("merkledag") @@ -520,7 +520,7 @@ func (n *ProtoNode) Resolve(path []string) (interface{}, []string, error) { // and the path without the consumed element. func (n *ProtoNode) ResolveLink(path []string) (*format.Link, []string, error) { if len(path) == 0 { - return nil, nil, fmt.Errorf("end of path, no more links to resolve") + return nil, nil, errors.New("end of path, no more links to resolve") } lnk, err := n.GetNodeLink(path[0]) diff --git a/ipld/merkledag/readonly.go b/ipld/merkledag/readonly.go index 36242fbeb..ec0f065e2 100644 --- a/ipld/merkledag/readonly.go +++ b/ipld/merkledag/readonly.go @@ -1,13 +1,13 @@ package merkledag import ( - "fmt" + "errors" ipld "github.com/ipfs/go-ipld-format" ) // ErrReadOnly is used when a read-only datastructure is written to. -var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService") +var ErrReadOnly = errors.New("cannot write to readonly DAGService") // NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService // implementation that returns ErrReadOnly when its 'write' methods are diff --git a/ipld/merkledag/test/dag_generator.go b/ipld/merkledag/test/dag_generator.go index ec6fba091..41f6c267d 100644 --- a/ipld/merkledag/test/dag_generator.go +++ b/ipld/merkledag/test/dag_generator.go @@ -3,6 +3,7 @@ package mdutils import ( "context" "fmt" + "strconv" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" @@ -70,7 +71,7 @@ func (dg *DAGGenerator) generate(adder func(ctx context.Context, node format.Nod func (dg *DAGGenerator) encodeBlock(adder func(ctx context.Context, node format.Node) error, links ...*format.Link) (cid.Cid, uint64, error) { dg.seq++ nd := &merkledag.ProtoNode{} - nd.SetData([]byte(fmt.Sprint(dg.seq))) + nd.SetData([]byte(strconv.Itoa(dg.seq))) for i, link := range links { err := nd.AddRawLink(fmt.Sprintf("link-%d", i), link) if err != nil { diff --git a/ipld/unixfs/hamt/hamt.go b/ipld/unixfs/hamt/hamt.go index fc6cda797..a57ddad41 100644 --- a/ipld/unixfs/hamt/hamt.go +++ b/ipld/unixfs/hamt/hamt.go @@ -24,6 +24,7 @@ package hamt import ( "context" + "errors" "fmt" "os" "sync" @@ -141,11 +142,11 @@ func NewHamtFromDag(dserv ipld.DAGService, nd ipld.Node) (*Shard, error) { } if fsn.Type() != format.THAMTShard { - return nil, fmt.Errorf("node was not a dir shard") + return nil, errors.New("node was not a dir shard") } if fsn.HashType() != HashMurmur3 { - return nil, fmt.Errorf("only murmur3 supported as hash function") + return nil, errors.New("only murmur3 supported as hash function") } size := int(fsn.Fanout()) @@ -451,7 +452,7 @@ func (ds *Shard) walkChildren(processLinkValues func(formattedLink *ipld.Link) e case shardLink: res.cids = append(res.cids, lnk.Cid) default: - return nil, fmt.Errorf("unsupported shard link type") + return nil, errors.New("unsupported shard link type") } } else { @@ -935,11 +936,11 @@ func (s *childer) each(ctx context.Context, cb func(*Shard) error) error { func (s *childer) check(sliceIndex int) error { if sliceIndex >= len(s.children) || sliceIndex < 0 { - return fmt.Errorf("invalid index passed to operate children (likely corrupt bitfield)") + return errors.New("invalid index passed to operate children (likely corrupt bitfield)") } if len(s.children) != len(s.links) { - return fmt.Errorf("inconsistent lengths between children array and Links array") + return errors.New("inconsistent lengths between children array and Links array") } return nil diff --git a/ipld/unixfs/hamt/hamt_test.go b/ipld/unixfs/hamt/hamt_test.go index 2defc0d3e..1946bbd7c 100644 --- a/ipld/unixfs/hamt/hamt_test.go +++ b/ipld/unixfs/hamt/hamt_test.go @@ -2,10 +2,12 @@ package hamt import ( "context" + "errors" "fmt" "math/rand" "os" "sort" + "strconv" "testing" "time" @@ -80,7 +82,7 @@ func assertLink(s *Shard, name string, found bool) error { func assertLinksEqual(linksA []*ipld.Link, linksB []*ipld.Link) error { if len(linksA) != len(linksB) { - return fmt.Errorf("links arrays are different sizes") + return errors.New("links arrays are different sizes") } sort.Stable(dag.LinkSlice(linksA)) @@ -88,15 +90,15 @@ func assertLinksEqual(linksA []*ipld.Link, linksB []*ipld.Link) error { for i, a := range linksA { b := linksB[i] if a.Name != b.Name { - return fmt.Errorf("links names mismatch") + return errors.New("links names mismatch") } if a.Cid.String() != b.Cid.String() { - return fmt.Errorf("link hashes dont match") + return errors.New("link hashes dont match") } if a.Size != b.Size { - return fmt.Errorf("link sizes not the same") + return errors.New("link sizes not the same") } } @@ -682,7 +684,7 @@ func BenchmarkHAMTWalk(b *testing.B) { } for j := 0; j < 1000; j++ { - err = s.Set(ctx, fmt.Sprintf("%d", j), ft.EmptyDirNode()) + err = s.Set(ctx, strconv.Itoa(j), ft.EmptyDirNode()) if err != nil { b.Fatal(err) } @@ -725,7 +727,7 @@ func BenchmarkHAMTSet(b *testing.B) { b.Fatal(err) } - err = s.Set(context.TODO(), fmt.Sprint(i), ft.EmptyDirNode()) + err = s.Set(context.TODO(), strconv.Itoa(i), ft.EmptyDirNode()) if err != nil { b.Fatal(err) } diff --git a/ipld/unixfs/hamt/util.go b/ipld/unixfs/hamt/util.go index e599be2ce..66369b912 100644 --- a/ipld/unixfs/hamt/util.go +++ b/ipld/unixfs/hamt/util.go @@ -1,7 +1,7 @@ package hamt import ( - "fmt" + "errors" "math/bits" "github.com/ipfs/boxo/ipld/unixfs/internal" @@ -33,7 +33,7 @@ func mkmask(n int) byte { // error if there aren't enough bits. func (hb *hashBits) Next(i int) (int, error) { if hb.consumed+i > len(hb.b)*8 { - return 0, fmt.Errorf("sharded directory too deep") + return 0, errors.New("sharded directory too deep") } return hb.next(i), nil } @@ -64,11 +64,11 @@ func (hb *hashBits) next(i int) int { func Logtwo(v int) (int, error) { if v <= 0 { - return 0, fmt.Errorf("hamt size should be a power of two") + return 0, errors.New("hamt size should be a power of two") } lg2 := bits.TrailingZeros(uint(v)) if 1<