Repository: nats-io/nsc (go)

Issue:
nsc sign with `-K` panics if seed is provided
```bash
synadia@malaga ~/D/c/s/g/a/n/b/conf> nsc add user a -K SAAFMSZMS2DGM46QHI5B65THHEXEECUJ734IRSPYNLDIJJFEB2W6TQAHCU
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x135c3e6]

goroutine 1 [running]:
github.com/nats-io/nsc/cmd/store.(*Report).updateCode(0x0, 0x166f28a)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/store/status.go:160 +0x26
github.com/nats-io/nsc/cmd/store.(*Report).Message(0x0, 0xc0001fa000, 0xc00025b3e0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/store/status.go:177 +0x2b
github.com/nats-io/nsc/cmd.run(0x173e968, 0xc00025b3e0, 0x1659400, 0xc0001a2380, 0x173e968, 0xc00025b3e0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/action.go:146 +0x216
github.com/nats-io/nsc/cmd.RunAction(0xc0001fa000, 0xc00025a990, 0x1, 0x3, 0x1659400, 0xc0001a2380, 0x0, 0x0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/action.go:112 +0xa5
github.com/nats-io/nsc/cmd.CreateAddUserCmd.func1(0xc0001fa000, 0xc00025a990, 0x1, 0x3, 0x0, 0x0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/adduser.go:72 +0x5e
github.com/spf13/cobra.(*Command).execute(0xc0001fa000, 0xc00025a900, 0x3, 0x3, 0xc0001fa000, 0xc00025a900)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/vendor/github.com/spf13/cobra/command.go:762 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0x1a409e0, 0x1f00ee8, 0x0, 0x0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/vendor/github.com/spf13/cobra/command.go:852 +0x2fe
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/vendor/github.com/spf13/cobra/command.go:800
github.com/nats-io/nsc/cmd.ExecuteWithWriter(0x17302a0, 0xc00013a010, 0xc00013a010, 0x17302a0)
        /Users/synadia/Dropbox/code/src/github.com/nats-io/nsc/cmd/root.go:185 +0x52
```

Pull request description:
[fixed] panic when signing with -K and a key that is not a signing key
fixes #420

Signed-off-by: Matthias Hanel <mh@synadia.com>

Patch:
diff --git a/cmd/adduser.go b/cmd/adduser.go
index 2e41518..6f2d203 100644
--- a/cmd/adduser.go
+++ b/cmd/adduser.go
@@ -315,13 +315,13 @@ func (p *AddUserParams) Run(ctx ActionCtx) (store.Status, error) {
 	}
 
 	st, err := ctx.StoreCtx().Store.StoreClaim([]byte(token))
-	if err != nil {
-		r.AddFromError(err)
-		return st, err
-	}
 	if st != nil {
 		r.Add(st)
 	}
+	if err != nil {
+		r.AddFromError(err)
+		return r, err
+	}
 
 	// store the key
 	if p.pkOrPath == "" {


Test patch:
diff --git a/cmd/signerparams_test.go b/cmd/signerparams_test.go
index 39ae4dc..6f28ca8 100644
--- a/cmd/signerparams_test.go
+++ b/cmd/signerparams_test.go
@@ -204,3 +204,21 @@ func Test_SignerParamsHomePath(t *testing.T) {
 	_, _, err = ExecuteCmd(createSignerCmd(nkeys.PrefixByteOperator, false, ts.OperatorKey), "-K", tfn)
 	require.NoError(t, err)
 }
+
+func Test_SignerParamsSeed(t *testing.T) {
+	ts := NewTestStore(t, "O")
+	defer ts.Done(t)
+
+	ts.AddAccount(t, "A")
+	s, pk, _ := CreateAccountKey(t)
+
+	_, stdErr, err := ExecuteCmd(HoistRootFlags(CreateAddUserCmd()), "--name", "a", "-K", string(s))
+	require.Error(t, err)
+	require.Contains(t, stdErr, "is not in the store")
+
+	_, _, err = ExecuteCmd(createEditAccount(), "--sk", pk)
+	require.NoError(t, err)
+
+	_, _, err = ExecuteCmd(HoistRootFlags(CreateAddUserCmd()), "--name", "a", "-K", string(s))
+	require.NoError(t, err)
+}