fix(client/keys): don't return when key not found in keys delete (#24041)

Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
Hoang Do
2025-03-19 09:21:36 -04:00
committed by GitHub
co-authored by Alex | Interchain Labs
parent 998a124bd4
commit 97dad50388
3 changed files with 10 additions and 3 deletions
+2 -1
View File
@@ -37,7 +37,8 @@ private keys stored in a ledger device cannot be deleted with the CLI.
for _, name := range args {
k, err := clientCtx.Keyring.Key(name)
if err != nil {
return err
cmd.PrintErrf("key %s not found\n", name)
continue
}
// confirm deletion, unless -y is passed
+7 -2
View File
@@ -1,6 +1,7 @@
package keys
import (
"bytes"
"context"
"fmt"
"testing"
@@ -20,9 +21,11 @@ import (
func Test_runDeleteCmd(t *testing.T) {
// Now add a temporary keybase
kbHome := t.TempDir()
errBuf := new(bytes.Buffer)
cmd := DeleteKeyCommand()
cmd.Flags().AddFlagSet(Commands().PersistentFlags())
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
cmd.SetErr(errBuf)
yesF, _ := cmd.Flags().GetBool(flagYes)
forceF, _ := cmd.Flags().GetBool(flagForce)
@@ -53,8 +56,10 @@ func Test_runDeleteCmd(t *testing.T) {
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
err = cmd.ExecuteContext(ctx)
require.Error(t, err)
require.EqualError(t, err, "blah.info: key not found")
require.NoError(t, err)
output := errBuf.String()
require.Contains(t, output, "key blah not found")
// User confirmation missing
cmd.SetArgs([]string{