From 7679a17bc667645685026fe21696dc09932d15e7 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 3 Nov 2021 19:36:11 +0300 Subject: [PATCH] cli: provide better error message in case of password read failure --- cli/smartcontract/smart_contract.go | 2 +- cli/wallet/validator.go | 2 +- cli/wallet/wallet.go | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index c66659d66..4c74711d7 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -811,7 +811,7 @@ func getUnlockedAccount(wall *wallet.Wallet, addr util.Uint160) (*wallet.Account rawPass, err := input.ReadPassword( fmt.Sprintf("Enter account %s password > ", address.Uint160ToString(addr))) if err != nil { - return nil, cli.NewExitError(err, 1) + return nil, cli.NewExitError(fmt.Errorf("Error reading password: %w", err), 1) } pass := strings.TrimRight(string(rawPass), "\n") err = acc.Decrypt(pass, wall.Scrypt) diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index 16f754ae4..a524be3a1 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -205,7 +205,7 @@ func getDecryptedAccount(ctx *cli.Context, wall *wallet.Wallet, addr util.Uint16 } if pass, err := input.ReadPassword("Password > "); err != nil { - fmt.Println("ERROR", pass, err) + fmt.Println("Error reading password", err) return nil, err } else if err := acc.Decrypt(pass, wall.Scrypt); err != nil { return nil, err diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 5b44b51b0..581cfd834 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -302,7 +302,7 @@ func convertWallet(ctx *cli.Context) error { for _, acc := range wall.Accounts { pass, err := input.ReadPassword(fmt.Sprintf("Enter passphrase for account %s (label '%s') > ", acc.Address, acc.Label)) if err != nil { - return cli.NewExitError(err, 1) + return cli.NewExitError(fmt.Errorf("Error reading password: %w", err), 1) } newAcc, err := acc.convert(pass, wall.Scrypt) if err != nil { @@ -372,7 +372,7 @@ loop: if decrypt { pass, err := input.ReadPassword("Enter password > ") if err != nil { - return cli.NewExitError(err, 1) + return cli.NewExitError(fmt.Errorf("Error reading password: %w", err), 1) } pk, err := keys.NEP2Decrypt(wif, pass, wall.Scrypt) @@ -567,7 +567,7 @@ func dumpWallet(ctx *cli.Context) error { if ctx.Bool("decrypt") { pass, err := input.ReadPassword("Enter wallet password > ") if err != nil { - return cli.NewExitError(err, 1) + return cli.NewExitError(fmt.Errorf("Error reading password: %w", err), 1) } for i := range wall.Accounts { // Just testing the decryption here. @@ -656,11 +656,11 @@ func readAccountInfo() (string, string, error) { rawName, _ := input.ReadLine("Enter the name of the account > ") phrase, err := input.ReadPassword("Enter passphrase > ") if err != nil { - return "", "", err + return "", "", fmt.Errorf("Error reading password: %w", err) } phraseCheck, err := input.ReadPassword("Confirm passphrase > ") if err != nil { - return "", "", err + return "", "", fmt.Errorf("Error reading password: %w", err) } if phrase != phraseCheck { @@ -692,7 +692,7 @@ func newAccountFromWIF(w io.Writer, wif string, scrypt keys.ScryptParams) (*wall if len(wif) == 58 { pass, err := input.ReadPassword("Enter password > ") if err != nil { - return nil, err + return nil, fmt.Errorf("Error reading password: %w", err) } return wallet.NewAccountFromEncryptedWIF(wif, pass, scrypt)