mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 06:57:40 +08:00
refactor: using error is instead of == (#10093)
This commit is contained in:
@ -82,7 +82,7 @@ func ManageFdLimit() (changed bool, newLimit uint64, err error) {
|
||||
// set the soft value
|
||||
err = setLimit(targetLimit, hard)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error setting ulimit without hard limit: %s", err)
|
||||
err = fmt.Errorf("error setting ulimit without hard limit: %w", err)
|
||||
break
|
||||
}
|
||||
newLimit = targetLimit
|
||||
@ -107,7 +107,7 @@ func ManageFdLimit() (changed bool, newLimit uint64, err error) {
|
||||
break
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("error setting: ulimit: %s", err)
|
||||
err = fmt.Errorf("error setting: ulimit: %w", err)
|
||||
}
|
||||
|
||||
return newLimit > 0, newLimit, err
|
||||
|
@ -36,7 +36,7 @@ func (c *Config) BootstrapPeers() ([]peer.AddrInfo, error) {
|
||||
func DefaultBootstrapPeers() ([]peer.AddrInfo, error) {
|
||||
ps, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %s
|
||||
return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %w
|
||||
This is a problem with the ipfs codebase. Please report it to the dev team`, err)
|
||||
}
|
||||
return ps, nil
|
||||
|
@ -117,7 +117,7 @@ func FromMap(v map[string]interface{}) (*Config, error) {
|
||||
}
|
||||
var conf Config
|
||||
if err := json.NewDecoder(buf).Decode(&conf); err != nil {
|
||||
return nil, fmt.Errorf("failure to decode config: %s", err)
|
||||
return nil, fmt.Errorf("failure to decode config: %w", err)
|
||||
}
|
||||
return &conf, nil
|
||||
}
|
||||
@ -129,7 +129,7 @@ func ToMap(conf *Config) (map[string]interface{}, error) {
|
||||
}
|
||||
var m map[string]interface{}
|
||||
if err := json.NewDecoder(buf).Decode(&m); err != nil {
|
||||
return nil, fmt.Errorf("failure to decode config: %s", err)
|
||||
return nil, fmt.Errorf("failure to decode config: %w", err)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@ -140,11 +140,11 @@ func (c *Config) Clone() (*Config, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := json.NewEncoder(&buf).Encode(c); err != nil {
|
||||
return nil, fmt.Errorf("failure to encode config: %s", err)
|
||||
return nil, fmt.Errorf("failure to encode config: %w", err)
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(&buf).Decode(&newConfig); err != nil {
|
||||
return nil, fmt.Errorf("failure to decode config: %s", err)
|
||||
return nil, fmt.Errorf("failure to decode config: %w", err)
|
||||
}
|
||||
|
||||
return &newConfig, nil
|
||||
|
@ -28,7 +28,7 @@ func ReadConfigFile(filename string, cfg interface{}) error {
|
||||
}
|
||||
defer f.Close()
|
||||
if err := json.NewDecoder(f).Decode(cfg); err != nil {
|
||||
return fmt.Errorf("failure to decode config: %s", err)
|
||||
return fmt.Errorf("failure to decode config: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ func (r *FSRepo) openConfig() error {
|
||||
func (r *FSRepo) openUserResourceOverrides() error {
|
||||
// This filepath is documented in docs/libp2p-resource-management.md and be kept in sync.
|
||||
err := serialize.ReadConfigFile(filepath.Join(r.path, "libp2p-resource-limit-overrides.json"), &r.userResourceOverrides)
|
||||
if err == serialize.ErrNotInitialized {
|
||||
if errors.Is(err, serialize.ErrNotInitialized) {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
|
@ -66,7 +66,7 @@ func (f *HttpFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, gwURL, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("http.NewRequest error: %s", err)
|
||||
return nil, fmt.Errorf("http.NewRequest error: %w", err)
|
||||
}
|
||||
|
||||
if f.userAgent != "" {
|
||||
@ -75,14 +75,14 @@ func (f *HttpFetcher) Fetch(ctx context.Context, filePath string) ([]byte, error
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("http.DefaultClient.Do error: %s", err)
|
||||
return nil, fmt.Errorf("http.DefaultClient.Do error: %w", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
defer resp.Body.Close()
|
||||
mes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading error body: %s", err)
|
||||
return nil, fmt.Errorf("error reading error body: %w", err)
|
||||
}
|
||||
return nil, fmt.Errorf("GET %s error: %s: %s", gwURL, resp.Status, string(mes))
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
|
||||
}
|
||||
fromVer, err := RepoVersion(ipfsDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get repo version: %s", err)
|
||||
return fmt.Errorf("could not get repo version: %w", err)
|
||||
}
|
||||
if fromVer == targetVer {
|
||||
// repo already at target version number
|
||||
@ -87,7 +87,7 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
|
||||
logger.Println("Running migration", migration, "...")
|
||||
err = runMigration(ctx, binPaths[migration], ipfsDir, revert, logger)
|
||||
if err != nil {
|
||||
return fmt.Errorf("migration %s failed: %s", migration, err)
|
||||
return fmt.Errorf("migration %s failed: %w", migration, err)
|
||||
}
|
||||
}
|
||||
logger.Printf("Success: fs-repo migrated to version %d.\n", targetVer)
|
||||
@ -98,7 +98,7 @@ func RunMigration(ctx context.Context, fetcher Fetcher, targetVer int, ipfsDir s
|
||||
func NeedMigration(target int) (bool, error) {
|
||||
vnum, err := RepoVersion("")
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("could not get repo version: %s", err)
|
||||
return false, fmt.Errorf("could not get repo version: %w", err)
|
||||
}
|
||||
|
||||
return vnum != target, nil
|
||||
@ -171,7 +171,7 @@ func GetMigrationFetcher(downloadSources []string, distPath string, newIpfsFetch
|
||||
default:
|
||||
u, err := url.Parse(src)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bad gateway address: %s", err)
|
||||
return nil, fmt.Errorf("bad gateway address: %w", err)
|
||||
}
|
||||
switch u.Scheme {
|
||||
case "":
|
||||
@ -293,7 +293,7 @@ func fetchMigrations(ctx context.Context, fetcher Fetcher, needed []string, dest
|
||||
if len(fails) != 0 {
|
||||
err = fmt.Errorf("failed to download migrations: %s", strings.Join(fails, " "))
|
||||
if ctx.Err() != nil {
|
||||
err = fmt.Errorf("%s, %s", ctx.Err(), err)
|
||||
err = fmt.Errorf("%s, %w", ctx.Err(), err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func DistVersions(ctx context.Context, fetcher Fetcher, dist string, sortDesc bo
|
||||
vers = append(vers, ver)
|
||||
}
|
||||
if scan.Err() != nil {
|
||||
return nil, fmt.Errorf("could not read versions: %s", scan.Err())
|
||||
return nil, fmt.Errorf("could not read versions: %w", scan.Err())
|
||||
}
|
||||
|
||||
if sortDesc {
|
||||
|
@ -2,6 +2,7 @@ package routing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -103,7 +104,7 @@ func (c *Composer) SearchValue(ctx context.Context, key string, opts ...routing.
|
||||
ch, err := c.GetValueRouter.SearchValue(ctx, key, opts...)
|
||||
|
||||
// avoid nil channels on implementations not supporting SearchValue method.
|
||||
if err == routing.ErrNotFound && ch == nil {
|
||||
if errors.Is(err, routing.ErrNotFound) && ch == nil {
|
||||
out := make(chan []byte)
|
||||
close(out)
|
||||
return out, err
|
||||
|
@ -175,7 +175,7 @@ func (tr *tarReader) Read(b []byte) (int, error) {
|
||||
tr.hdrBuf = bytes.NewReader(hndpb.Data())
|
||||
|
||||
dataNd, err := hndpb.GetLinkedProtoNode(tr.ctx, tr.ds, "data")
|
||||
if err != nil && err != dag.ErrLinkNotFound {
|
||||
if err != nil && !errors.Is(err, dag.ErrLinkNotFound) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user