From f93e8c58d8b92e1e8d998fb9525e99d187a6dced Mon Sep 17 00:00:00 2001 From: Kerem Date: Thu, 27 Apr 2017 20:56:00 +0300 Subject: [PATCH] code review improvements - change core.IpfsNode as first arg - check keylookup err to propagate validation errors from lower levels --- core/commands/publish.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/commands/publish.go b/core/commands/publish.go index 70eca056ec7b..9db8b7bcc606 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -10,6 +10,7 @@ import ( cmds "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" + keystore "github.com/ipfs/go-ipfs/keystore" path "github.com/ipfs/go-ipfs/path" crypto "gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto" @@ -121,7 +122,7 @@ Alternatively, publish an using a valid PeerID(as listed by 'ipfs ke } kname, _, _ := req.Option("key").String() - k, err := keylookup(kname, n) + k, err := keylookup(n, kname) if err != nil { res.SetError(err, cmds.ErrNormal) return @@ -182,13 +183,17 @@ func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.P }, nil } -func keylookup(k string, n *core.IpfsNode) (crypto.PrivKey, error) { +func keylookup(n *core.IpfsNode, k string) (crypto.PrivKey, error) { res, err := n.GetKey(k) if res != nil { return res, nil } + if err != nil && err != keystore.ErrNoSuchKey { + return nil, err + } + keys, err := n.Repo.Keystore().List() if err != nil { return nil, err