Skip to content

Commit

Permalink
fix: It is recommended to use the fmt.Errorf method with parameters i…
Browse files Browse the repository at this point in the history
…nstead of the errors.New method without parameters.

Signed-off-by: RiceChuan <[email protected]>
  • Loading branch information
RiceChuan committed Dec 24, 2024
1 parent 1fe8c69 commit 99c6a8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/commands/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Example:
allowCustom, _ := req.Options[allowCustomProtocolOptionName].(bool)

if !allowCustom && !strings.HasPrefix(string(proto), P2PProtoPrefix) {
return errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace")
return fmt.Errorf("protocol name must be within '" + P2PProtoPrefix + "' namespace")
}

return forwardLocal(n.Context(), n.P2P, n.Peerstore, proto, listen, targets)
Expand All @@ -154,7 +154,7 @@ func parseIpfsAddr(addr string) (*peer.AddrInfo, error) {
return nil, err
}
if len(addrs) == 0 {
return nil, errors.New("fail to resolve the multiaddr:" + multiaddr.String())
return nil, fmt.Errorf("fail to resolve the multiaddr:" + multiaddr.String())
}
var info peer.AddrInfo
for _, addr := range addrs {
Expand Down Expand Up @@ -228,7 +228,7 @@ Example:
reportPeerID, _ := req.Options[reportPeerIDOptionName].(bool)

if !allowCustom && !strings.HasPrefix(string(proto), P2PProtoPrefix) {
return errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace")
return fmt.Errorf("protocol name must be within '" + P2PProtoPrefix + "' namespace")
}

_, err = n.P2P.ForwardRemote(n.Context(), proto, target, reportPeerID)
Expand Down

0 comments on commit 99c6a8e

Please sign in to comment.