From 113b2cd6cfee5a3c737a9a6bf59bc486f7fb6045 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 22 Oct 2020 12:31:03 -0500 Subject: [PATCH] Clarify `No Wallet Found` Error Messages (#7609) * clarify no wallet found error messages * extract error * fix tests Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- validator/accounts/accounts_backup.go | 4 +--- validator/accounts/accounts_delete.go | 4 +--- validator/accounts/accounts_exit.go | 4 +--- validator/accounts/accounts_list.go | 4 +--- validator/accounts/wallet/wallet.go | 4 +++- validator/accounts/wallet/wallet_test.go | 2 +- validator/accounts/wallet_edit.go | 4 +--- validator/node/node.go | 2 +- validator/rpc/wallet.go | 1 - 9 files changed, 10 insertions(+), 19 deletions(-) diff --git a/validator/accounts/accounts_backup.go b/validator/accounts/accounts_backup.go index e62be388641..cfc5a2c7a45 100644 --- a/validator/accounts/accounts_backup.go +++ b/validator/accounts/accounts_backup.go @@ -41,9 +41,7 @@ const ( // keystore.json files, which are compatible with importing in other eth2 clients. func BackupAccountsCli(cliCtx *cli.Context) error { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New( - "no wallet found, nothing to backup. Create a new wallet by running wallet create", - ) + return nil, wallet.ErrNoWalletFound }) if err != nil { return errors.Wrap(err, "could not initialize wallet") diff --git a/validator/accounts/accounts_delete.go b/validator/accounts/accounts_delete.go index afc2b82b55f..4f653135aa2 100644 --- a/validator/accounts/accounts_delete.go +++ b/validator/accounts/accounts_delete.go @@ -28,9 +28,7 @@ type DeleteAccountConfig struct { // This function uses the CLI to extract necessary values. func DeleteAccountCli(cliCtx *cli.Context) error { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New( - "no wallet found, nothing to delete", - ) + return nil, wallet.ErrNoWalletFound }) if err != nil { return errors.Wrap(err, "could not open wallet") diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index 35896e4f00f..5c0dc22417f 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -76,9 +76,7 @@ func ExitAccountsCli(cliCtx *cli.Context, r io.Reader) error { func prepareWallet(cliCtx *cli.Context) ([][48]byte, keymanager.IKeymanager, error) { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New( - "no wallet found, no accounts to exit", - ) + return nil, wallet.ErrNoWalletFound }) if err != nil { return nil, nil, errors.Wrap(err, "could not open wallet") diff --git a/validator/accounts/accounts_list.go b/validator/accounts/accounts_list.go index ca58f75cf8d..d5466c2038b 100644 --- a/validator/accounts/accounts_list.go +++ b/validator/accounts/accounts_list.go @@ -21,9 +21,7 @@ import ( // ListAccountsCli displays all available validator accounts in a Prysm wallet. func ListAccountsCli(cliCtx *cli.Context) error { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New( - "no wallet found, no accounts to list", - ) + return nil, wallet.ErrNoWalletFound }) if err != nil { return errors.Wrap(err, "could not open wallet") diff --git a/validator/accounts/wallet/wallet.go b/validator/accounts/wallet/wallet.go index e2e8a730c73..6ad615dfa61 100644 --- a/validator/accounts/wallet/wallet.go +++ b/validator/accounts/wallet/wallet.go @@ -49,7 +49,9 @@ const ( var ( // ErrNoWalletFound signifies there was no wallet directory found on-disk. ErrNoWalletFound = errors.New( - "no wallet found at path, please create a new wallet using `./prysm.sh validator wallet create`", + "no wallet found. You can create a new wallet with validator wallet create." + + "If you already did, perhaps you created a wallet in a custom directory, which you can specify using " + + "--wallet-dir=/path/to/my/wallet", ) // KeymanagerKindSelections as friendly text. KeymanagerKindSelections = map[keymanager.Kind]string{ diff --git a/validator/accounts/wallet/wallet_test.go b/validator/accounts/wallet/wallet_test.go index 71ccdeedd2c..262fa41a50c 100644 --- a/validator/accounts/wallet/wallet_test.go +++ b/validator/accounts/wallet/wallet_test.go @@ -140,7 +140,7 @@ func Test_IsValid_RandomFiles(t *testing.T) { require.NoError(t, os.MkdirAll(path, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory") valid, err = wallet.IsValid(path) - require.ErrorContains(t, "no wallet found at path", err) + require.ErrorContains(t, "no wallet found", err) require.Equal(t, false, valid) walletDir := filepath.Join(path, "direct") diff --git a/validator/accounts/wallet_edit.go b/validator/accounts/wallet_edit.go index f072b7bf37b..8f92befc241 100644 --- a/validator/accounts/wallet_edit.go +++ b/validator/accounts/wallet_edit.go @@ -16,9 +16,7 @@ import ( // for HD wallets, and more. func EditWalletConfigurationCli(cliCtx *cli.Context) error { w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New( - "no wallet found, no configuration to edit", - ) + return nil, wallet.ErrNoWalletFound }) if err != nil { return errors.Wrap(err, "could not open wallet") diff --git a/validator/node/node.go b/validator/node/node.go index 91488f0edac..ddcbd4531b6 100644 --- a/validator/node/node.go +++ b/validator/node/node.go @@ -170,7 +170,7 @@ func (s *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error { } else { // Read the wallet from the specified path. w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) { - return nil, errors.New("no wallet found, create a new one with validator wallet create") + return nil, wallet.ErrNoWalletFound }) if err != nil { return errors.Wrap(err, "could not open wallet") diff --git a/validator/rpc/wallet.go b/validator/rpc/wallet.go index 81e060ad8fa..5c65ab7b161 100644 --- a/validator/rpc/wallet.go +++ b/validator/rpc/wallet.go @@ -23,7 +23,6 @@ import ( const ( checkExistsErrMsg = "Could not check if wallet exists" checkValidityErrMsg = "Could not check if wallet is valid" - noWalletMsg = "No wallet found at path" invalidWalletMsg = "Directory does not contain a valid wallet" )