1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 15:06:47 +08:00

refactor: using error is instead of == (#10093)

This commit is contained in:
Kay
2023-08-22 18:23:29 +03:30
committed by GitHub
parent 1e5ce93659
commit 2b7c20fc66
10 changed files with 21 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}