@cryptotaxi247 / kubo / commits / 642e58ef3

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

Andi committed Dec 11, 2024 at 05:50 UTC 642e58ef3b17784662b4758214a1a58be92af17f
20 files changed +37 -32
cmd/ipfs/kubo/daemon.go
+2 -2
@@ -295,7 +295,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
295 if !domigrate {
296 fmt.Println("Not running migrations of fs-repo now.")
297 fmt.Println("Please get fs-repo-migrations from https://dist.ipfs.tech")
298 - return fmt.Errorf("fs-repo requires migration")
298 + return errors.New("fs-repo requires migration")
299 }
300
301 // Read Migration section of IPFS config
@@ -436,7 +436,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
436 ncfg.Routing = libp2p.NilRouterOption
437 case routingOptionCustomKwd:
438 if cfg.Routing.AcceleratedDHTClient.WithDefault(config.DefaultAcceleratedDHTClient) {
439 - 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")
439 + 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")
440 }
441 ncfg.Routing = libp2p.ConstructDelegatedRouting(
442 cfg.Routing.Routers,
cmd/ipfs/kubo/init.go
+2 -2
@@ -88,11 +88,11 @@ environment variable:
88 if it.Err() != nil {
89 return it.Err()
90 }
91 - return fmt.Errorf("file argument was nil")
91 + return errors.New("file argument was nil")
92 }
93 file := files.FileFromEntry(it)
94 if file == nil {
95 - return fmt.Errorf("expected a regular file")
95 + return errors.New("expected a regular file")
96 }
97
98 conf = &config.Config{}
core/commands/add.go
+1 -1
@@ -25,7 +25,7 @@ import (
25 )
26
27 // ErrDepthLimitExceeded indicates that the max depth has been exceeded.
28 -var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
28 +var ErrDepthLimitExceeded = errors.New("depth limit exceeded")
29
30 type TimeParts struct {
31 t *time.Time
core/commands/cat.go
+3 -3
@@ -2,7 +2,7 @@ package commands
2
3 import (
4 "context"
5 - "fmt"
5 + "errors"
6 "io"
7 "os"
8
@@ -43,13 +43,13 @@ var CatCmd = &cmds.Command{
43
44 offset, _ := req.Options[offsetOptionName].(int64)
45 if offset < 0 {
46 - return fmt.Errorf("cannot specify negative offset")
46 + return errors.New("cannot specify negative offset")
47 }
48
49 max, found := req.Options[lengthOptionName].(int64)
50
51 if max < 0 {
52 - return fmt.Errorf("cannot specify negative length")
52 + return errors.New("cannot specify negative length")
53 }
54 if !found {
55 max = -1
core/commands/cid.go
+3 -2
@@ -1,6 +1,7 @@
1 package commands
2
3 import (
4 + "errors"
5 "fmt"
6 "io"
7 "sort"
@@ -85,10 +86,10 @@ The optional format string is a printf style format string:
86 }
87 case "0":
88 if opts.newCodec != 0 && opts.newCodec != cid.DagProtobuf {
88 - return fmt.Errorf("cannot convert to CIDv0 with any codec other than dag-pb")
89 + return errors.New("cannot convert to CIDv0 with any codec other than dag-pb")
90 }
91 if baseStr != "" && baseStr != "base58btc" {
91 - return fmt.Errorf("cannot convert to CIDv0 with any multibase other than the implicit base58btc")
92 + return errors.New("cannot convert to CIDv0 with any multibase other than the implicit base58btc")
93 }
94 opts.verConv = toCidV0
95 case "1":
core/commands/dht.go
+1 -1
@@ -78,7 +78,7 @@ var queryDhtCmd = &cmds.Command{
78 }
79
80 if d, ok := client.(kademlia); !ok {
81 - return fmt.Errorf("dht client does not support GetClosestPeers")
81 + return errors.New("dht client does not support GetClosestPeers")
82 } else {
83 errCh := make(chan error, 1)
84 go func() {
core/commands/files.go
+1 -1
@@ -327,7 +327,7 @@ func statNode(nd ipld.Node, enc cidenc.Encoder) (*statOutput, error) {
327 Type: "file",
328 }, nil
329 default:
330 - return nil, fmt.Errorf("not unixfs node (proto or raw)")
330 + return nil, errors.New("not unixfs node (proto or raw)")
331 }
332 }
333
core/commands/id.go
+1 -1
@@ -81,7 +81,7 @@ EXAMPLE:
81 var err error
82 id, err = peer.Decode(req.Arguments[0])
83 if err != nil {
84 - return fmt.Errorf("invalid peer id")
84 + return errors.New("invalid peer id")
85 }
86 } else {
87 id = n.Identity
core/commands/keystore.go
+3 -2
@@ -5,6 +5,7 @@ import (
5 "crypto/ed25519"
6 "crypto/x509"
7 "encoding/pem"
8 + "errors"
9 "fmt"
10 "io"
11 "os"
@@ -101,12 +102,12 @@ var keyGenCmd = &cmds.Command{
102
103 typ, f := req.Options[keyStoreTypeOptionName].(string)
104 if !f {
104 - return fmt.Errorf("please specify a key type with --type")
105 + return errors.New("please specify a key type with --type")
106 }
107
108 name := req.Arguments[0]
109 if name == "self" {
109 - return fmt.Errorf("cannot create key with name 'self'")
110 + return errors.New("cannot create key with name 'self'")
111 }
112
113 opts := []options.KeyGenerateOption{options.Key.Type(typ)}
core/commands/p2p.go
+2 -2
@@ -250,7 +250,7 @@ func checkPort(target ma.Multiaddr) error {
250 if sport != "" {
251 return sport, nil
252 }
253 - return "", fmt.Errorf("address does not contain tcp or udp protocol")
253 + return "", errors.New("address does not contain tcp or udp protocol")
254 }
255
256 sport, err := getPort()
@@ -264,7 +264,7 @@ func checkPort(target ma.Multiaddr) error {
264 }
265
266 if port == 0 {
267 - return fmt.Errorf("port can not be 0")
267 + return errors.New("port can not be 0")
268 }
269
270 return nil
core/commands/routing.go
+1 -1
@@ -70,7 +70,7 @@ var findProvidersRoutingCmd = &cmds.Command{
70
71 numProviders, _ := req.Options[numProvidersOptionName].(int)
72 if numProviders < 1 {
73 - return fmt.Errorf("number of providers must be greater than 0")
73 + return errors.New("number of providers must be greater than 0")
74 }
75
76 c, err := cid.Parse(req.Arguments[0])
core/commands/stat.go
+2 -1
@@ -1,6 +1,7 @@
1 package commands
2
3 import (
4 + "errors"
5 "fmt"
6 "io"
7 "os"
@@ -100,7 +101,7 @@ Example:
101 }
102
103 if nd.Reporter == nil {
103 - return fmt.Errorf("bandwidth reporter disabled in config")
104 + return errors.New("bandwidth reporter disabled in config")
105 }
106
107 pstr, pfound := req.Options[statPeerOptionName].(string)
core/coreapi/coreapi.go
+1 -1
@@ -218,7 +218,7 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
218 cs = node.DefaultIpnsCacheSize
219 }
220 if cs < 0 {
221 - return nil, fmt.Errorf("cannot specify negative resolve cache size")
221 + return nil, errors.New("cannot specify negative resolve cache size")
222 }
223
224 nsOptions := []namesys.Option{
core/coreapi/key.go
+4 -4
@@ -65,7 +65,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
65 }
66
67 if name == "self" {
68 - return nil, fmt.Errorf("cannot create key with name 'self'")
68 + return nil, errors.New("cannot create key with name 'self'")
69 }
70
71 _, err = api.repo.Keystore().Get(name)
@@ -168,11 +168,11 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
168 ks := api.repo.Keystore()
169
170 if oldName == "self" {
171 - return nil, false, fmt.Errorf("cannot rename key with name 'self'")
171 + return nil, false, errors.New("cannot rename key with name 'self'")
172 }
173
174 if newName == "self" {
175 - return nil, false, fmt.Errorf("cannot overwrite key with name 'self'")
175 + return nil, false, errors.New("cannot overwrite key with name 'self'")
176 }
177
178 oldKey, err := ks.Get(oldName)
@@ -232,7 +232,7 @@ func (api *KeyAPI) Remove(ctx context.Context, name string) (coreiface.Key, erro
232 ks := api.repo.Keystore()
233
234 if name == "self" {
235 - return nil, fmt.Errorf("cannot remove key with name 'self'")
235 + return nil, errors.New("cannot remove key with name 'self'")
236 }
237
238 removed, err := ks.Get(name)
core/coreapi/name.go
+2 -1
@@ -2,6 +2,7 @@ package coreapi
2
3 import (
4 "context"
5 + "errors"
6 "fmt"
7 "strings"
8 "time"
@@ -214,5 +215,5 @@ func keylookup(self ci.PrivKey, kstore keystore.Keystore, k string) (ci.PrivKey,
215 }
216 }
217
217 - return nil, fmt.Errorf("no key by the given name or PeerID was found")
218 + return nil, errors.New("no key by the given name or PeerID was found")
219 }
core/coreapi/routing.go
+1 -1
@@ -109,7 +109,7 @@ func (api *RoutingAPI) FindProviders(ctx context.Context, p path.Path, opts ...c
109
110 numProviders := settings.NumProviders
111 if numProviders < 1 {
112 - return nil, fmt.Errorf("number of providers must be greater than 0")
112 + return nil, errors.New("number of providers must be greater than 0")
113 }
114
115 pchan := api.routing.FindProvidersAsync(ctx, rp.RootCid(), numProviders)
core/coreapi/unixfs.go
+1 -1
@@ -72,7 +72,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
72 //}
73
74 if settings.NoCopy && !(cfg.Experimental.FilestoreEnabled || cfg.Experimental.UrlstoreEnabled) {
75 - 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")
75 + 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")
76 }
77
78 addblockstore := api.blockstore
core/node/groups.go
+1 -1
@@ -260,7 +260,7 @@ func Online(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
260 ipnsCacheSize = DefaultIpnsCacheSize
261 }
262 if ipnsCacheSize < 0 {
263 - return fx.Error(fmt.Errorf("cannot specify negative resolve cache size"))
263 + return fx.Error(errors.New("cannot specify negative resolve cache size"))
264 }
265
266 // Republisher params
core/node/libp2p/rcmgr.go
+2 -1
@@ -3,6 +3,7 @@ package libp2p
3 import (
4 "context"
5 "encoding/json"
6 + "errors"
7 "fmt"
8 "os"
9 "path/filepath"
@@ -26,7 +27,7 @@ var rcmgrLogger = logging.Logger("rcmgr")
27
28 const NetLimitTraceFilename = "rcmgr.json.gz"
29
29 -var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
30 +var ErrNoResourceMgr = errors.New("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
31
32 func ResourceManager(repoPath string, cfg config.SwarmConfig, userResourceOverrides rcmgr.PartialLimitConfig) interface{} {
33 return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
core/node/libp2p/smux.go
+3 -3
@@ -1,7 +1,7 @@
1 package libp2p
2
3 import (
4 - "fmt"
4 + "errors"
5 "os"
6
7 "github.com/ipfs/kubo/config"
@@ -12,10 +12,10 @@ import (
12
13 func makeSmuxTransportOption(tptConfig config.Transports) (libp2p.Option, error) {
14 if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" {
15 - return nil, fmt.Errorf("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")
15 + return nil, errors.New("configuring muxers with LIBP2P_MUX_PREFS is no longer supported, use Swarm.Transports.Multiplexers")
16 }
17 if tptConfig.Multiplexers.Yamux < 0 {
18 - return nil, fmt.Errorf("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported")
18 + return nil, errors.New("running libp2p with Swarm.Transports.Multiplexers.Yamux disabled is not supported")
19 }
20
21 return libp2p.Muxer(yamux.ID, yamux.DefaultTransport), nil