Skip to content

Commit

Permalink
Clarify No Wallet Found Error Messages (#7609)
Browse files Browse the repository at this point in the history
* clarify no wallet found error messages

* extract error

* fix tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
rauljordan and prylabs-bulldozer[bot] committed Oct 22, 2020
1 parent 13af8a7 commit 113b2cd
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 19 deletions.
4 changes: 1 addition & 3 deletions validator/accounts/accounts_backup.go
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions validator/accounts/accounts_delete.go
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions validator/accounts/accounts_exit.go
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions validator/accounts/accounts_list.go
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion validator/accounts/wallet/wallet.go
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion validator/accounts/wallet/wallet_test.go
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions validator/accounts/wallet_edit.go
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion validator/node/node.go
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion validator/rpc/wallet.go
Expand Up @@ -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"
)

Expand Down

0 comments on commit 113b2cd

Please sign in to comment.