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

chore: use errors.New to replace fmt.Errorf with no parameters #10617

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions cmd/ipfs/kubo/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
if !domigrate {
fmt.Println("Not running migrations of fs-repo now.")
fmt.Println("Please get fs-repo-migrations from https://dist.ipfs.tech")
return fmt.Errorf("fs-repo requires migration")
return errors.New("fs-repo requires migration")
}

// Read Migration section of IPFS config
Expand Down Expand Up @@ -436,7 +436,7 @@
ncfg.Routing = libp2p.NilRouterOption
case routingOptionCustomKwd:
if cfg.Routing.AcceleratedDHTClient.WithDefault(config.DefaultAcceleratedDHTClient) {
return fmt.Errorf("Routing.AcceleratedDHTClient option is set even tho Routing.Type is custom, using custom .AcceleratedDHTClient needs to be set on DHT routers individually")
return errors.New("Routing.AcceleratedDHTClient option is set even tho Routing.Type is custom, using custom .AcceleratedDHTClient needs to be set on DHT routers individually")

Check warning on line 439 in cmd/ipfs/kubo/daemon.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipfs/kubo/daemon.go#L439

Added line #L439 was not covered by tests
}
ncfg.Routing = libp2p.ConstructDelegatedRouting(
cfg.Routing.Routers,
Expand Down
4 changes: 2 additions & 2 deletions cmd/ipfs/kubo/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@
if it.Err() != nil {
return it.Err()
}
return fmt.Errorf("file argument was nil")
return errors.New("file argument was nil")

Check warning on line 91 in cmd/ipfs/kubo/init.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipfs/kubo/init.go#L91

Added line #L91 was not covered by tests
}
file := files.FileFromEntry(it)
if file == nil {
return fmt.Errorf("expected a regular file")
return errors.New("expected a regular file")

Check warning on line 95 in cmd/ipfs/kubo/init.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipfs/kubo/init.go#L95

Added line #L95 was not covered by tests
}

conf = &config.Config{}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// ErrDepthLimitExceeded indicates that the max depth has been exceeded.
var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
var ErrDepthLimitExceeded = errors.New("depth limit exceeded")

type TimeParts struct {
t *time.Time
Expand Down
6 changes: 3 additions & 3 deletions core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package commands

import (
"context"
"fmt"
"errors"
"io"
"os"

Expand Down Expand Up @@ -43,13 +43,13 @@ var CatCmd = &cmds.Command{

offset, _ := req.Options[offsetOptionName].(int64)
if offset < 0 {
return fmt.Errorf("cannot specify negative offset")
return errors.New("cannot specify negative offset")
}

max, found := req.Options[lengthOptionName].(int64)

if max < 0 {
return fmt.Errorf("cannot specify negative length")
return errors.New("cannot specify negative length")
}
if !found {
max = -1
Expand Down
5 changes: 3 additions & 2 deletions core/commands/cid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"errors"
"fmt"
"io"
"sort"
Expand Down Expand Up @@ -85,10 +86,10 @@
}
case "0":
if opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {
return fmt.Errorf("cannot convert to CIDv0 with any codec other than dag-pb")
return errors.New("cannot convert to CIDv0 with any codec other than dag-pb")

Check warning on line 89 in core/commands/cid.go

View check run for this annotation

Codecov / codecov/patch

core/commands/cid.go#L89

Added line #L89 was not covered by tests
}
if baseStr != "" && baseStr != "base58btc" {
return fmt.Errorf("cannot convert to CIDv0 with any multibase other than the implicit base58btc")
return errors.New("cannot convert to CIDv0 with any multibase other than the implicit base58btc")
}
opts.verConv = toCidV0
case "1":
Expand Down
2 changes: 1 addition & 1 deletion core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}

if d, ok := client.(kademlia); !ok {
return fmt.Errorf("dht client does not support GetClosestPeers")
return errors.New("dht client does not support GetClosestPeers")

Check warning on line 81 in core/commands/dht.go

View check run for this annotation

Codecov / codecov/patch

core/commands/dht.go#L81

Added line #L81 was not covered by tests
} else {
errCh := make(chan error, 1)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
Type: "file",
}, nil
default:
return nil, fmt.Errorf("not unixfs node (proto or raw)")
return nil, errors.New("not unixfs node (proto or raw)")

Check warning on line 330 in core/commands/files.go

View check run for this annotation

Codecov / codecov/patch

core/commands/files.go#L330

Added line #L330 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/commands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
var err error
id, err = peer.Decode(req.Arguments[0])
if err != nil {
return fmt.Errorf("invalid peer id")
return errors.New("invalid peer id")

Check warning on line 84 in core/commands/id.go

View check run for this annotation

Codecov / codecov/patch

core/commands/id.go#L84

Added line #L84 was not covered by tests
}
} else {
id = n.Identity
Expand Down
5 changes: 3 additions & 2 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"crypto/ed25519"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -101,12 +102,12 @@

typ, f := req.Options[keyStoreTypeOptionName].(string)
if !f {
return fmt.Errorf("please specify a key type with --type")
return errors.New("please specify a key type with --type")

Check warning on line 105 in core/commands/keystore.go

View check run for this annotation

Codecov / codecov/patch

core/commands/keystore.go#L105

Added line #L105 was not covered by tests
}

name := req.Arguments[0]
if name == "self" {
return fmt.Errorf("cannot create key with name 'self'")
return errors.New("cannot create key with name 'self'")

Check warning on line 110 in core/commands/keystore.go

View check run for this annotation

Codecov / codecov/patch

core/commands/keystore.go#L110

Added line #L110 was not covered by tests
}

opts := []options.KeyGenerateOption{options.Key.Type(typ)}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
if sport != "" {
return sport, nil
}
return "", fmt.Errorf("address does not contain tcp or udp protocol")
return "", errors.New("address does not contain tcp or udp protocol")

Check warning on line 253 in core/commands/p2p.go

View check run for this annotation

Codecov / codecov/patch

core/commands/p2p.go#L253

Added line #L253 was not covered by tests
}

sport, err := getPort()
Expand All @@ -264,7 +264,7 @@
}

if port == 0 {
return fmt.Errorf("port can not be 0")
return errors.New("port can not be 0")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

numProviders, _ := req.Options[numProvidersOptionName].(int)
if numProviders < 1 {
return fmt.Errorf("number of providers must be greater than 0")
return errors.New("number of providers must be greater than 0")

Check warning on line 73 in core/commands/routing.go

View check run for this annotation

Codecov / codecov/patch

core/commands/routing.go#L73

Added line #L73 was not covered by tests
}

c, err := cid.Parse(req.Arguments[0])
Expand Down
3 changes: 2 additions & 1 deletion core/commands/stat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -100,7 +101,7 @@
}

if nd.Reporter == nil {
return fmt.Errorf("bandwidth reporter disabled in config")
return errors.New("bandwidth reporter disabled in config")

Check warning on line 104 in core/commands/stat.go

View check run for this annotation

Codecov / codecov/patch

core/commands/stat.go#L104

Added line #L104 was not covered by tests
}

pstr, pfound := req.Options[statPeerOptionName].(string)
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
cs = node.DefaultIpnsCacheSize
}
if cs < 0 {
return nil, fmt.Errorf("cannot specify negative resolve cache size")
return nil, errors.New("cannot specify negative resolve cache size")

Check warning on line 221 in core/coreapi/coreapi.go

View check run for this annotation

Codecov / codecov/patch

core/coreapi/coreapi.go#L221

Added line #L221 was not covered by tests
}

nsOptions := []namesys.Option{
Expand Down
8 changes: 4 additions & 4 deletions core/coreapi/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}

if name == "self" {
return nil, fmt.Errorf("cannot create key with name 'self'")
return nil, errors.New("cannot create key with name 'self'")

Check warning on line 68 in core/coreapi/key.go

View check run for this annotation

Codecov / codecov/patch

core/coreapi/key.go#L68

Added line #L68 was not covered by tests
}

_, err = api.repo.Keystore().Get(name)
Expand Down Expand Up @@ -168,11 +168,11 @@
ks := api.repo.Keystore()

if oldName == "self" {
return nil, false, fmt.Errorf("cannot rename key with name 'self'")
return nil, false, errors.New("cannot rename key with name 'self'")
}

if newName == "self" {
return nil, false, fmt.Errorf("cannot overwrite key with name 'self'")
return nil, false, errors.New("cannot overwrite key with name 'self'")
}

oldKey, err := ks.Get(oldName)
Expand Down Expand Up @@ -232,7 +232,7 @@
ks := api.repo.Keystore()

if name == "self" {
return nil, fmt.Errorf("cannot remove key with name 'self'")
return nil, errors.New("cannot remove key with name 'self'")
}

removed, err := ks.Get(name)
Expand Down
3 changes: 2 additions & 1 deletion core/coreapi/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -214,5 +215,5 @@
}
}

return nil, fmt.Errorf("no key by the given name or PeerID was found")
return nil, errors.New("no key by the given name or PeerID was found")

Check warning on line 218 in core/coreapi/name.go

View check run for this annotation

Codecov / codecov/patch

core/coreapi/name.go#L218

Added line #L218 was not covered by tests
}
2 changes: 1 addition & 1 deletion core/coreapi/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

numProviders := settings.NumProviders
if numProviders < 1 {
return nil, fmt.Errorf("number of providers must be greater than 0")
return nil, errors.New("number of providers must be greater than 0")

Check warning on line 112 in core/coreapi/routing.go

View check run for this annotation

Codecov / codecov/patch

core/coreapi/routing.go#L112

Added line #L112 was not covered by tests
}

pchan := api.routing.FindProvidersAsync(ctx, rp.RootCid(), numProviders)
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
//}

if settings.NoCopy && !(cfg.Experimental.FilestoreEnabled || cfg.Experimental.UrlstoreEnabled) {
return path.ImmutablePath{}, fmt.Errorf("either the filestore or the urlstore must be enabled to use nocopy, see: https://github.com/ipfs/kubo/blob/master/docs/experimental-features.md#ipfs-filestore")
return path.ImmutablePath{}, errors.New("either the filestore or the urlstore must be enabled to use nocopy, see: https://github.com/ipfs/kubo/blob/master/docs/experimental-features.md#ipfs-filestore")
}

addblockstore := api.blockstore
Expand Down
2 changes: 1 addition & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
ipnsCacheSize = DefaultIpnsCacheSize
}
if ipnsCacheSize < 0 {
return fx.Error(fmt.Errorf("cannot specify negative resolve cache size"))
return fx.Error(errors.New("cannot specify negative resolve cache size"))

Check warning on line 263 in core/node/groups.go

View check run for this annotation

Codecov / codecov/patch

core/node/groups.go#L263

Added line #L263 was not covered by tests
}

// Republisher params
Expand Down
3 changes: 2 additions & 1 deletion core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package libp2p
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -26,7 +27,7 @@ var rcmgrLogger = logging.Logger("rcmgr")

const NetLimitTraceFilename = "rcmgr.json.gz"

var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
var ErrNoResourceMgr = errors.New("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")

func ResourceManager(repoPath string, cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
Expand Down
6 changes: 3 additions & 3 deletions core/node/libp2p/smux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package libp2p

import (
"fmt"
"errors"
"os"

"github.com/ipfs/kubo/config"
Expand All @@ -12,10 +12,10 @@

func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")
return nil, errors.New("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")

Check warning on line 15 in core/node/libp2p/smux.go

View check run for this annotation

Codecov / codecov/patch

core/node/libp2p/smux.go#L15

Added line #L15 was not covered by tests
}
if tptConfig.Multiplexers.Yamux < 0 {
return nil, fmt.Errorf("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported")
return nil, errors.New("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported")

Check warning on line 18 in core/node/libp2p/smux.go

View check run for this annotation

Codecov / codecov/patch

core/node/libp2p/smux.go#L18

Added line #L18 was not covered by tests
}

return libp2p.Muxer(yamux.ID, yamux.DefaultTransport), nil
Expand Down
Loading