lncli: improve error message for unlock commands
This commit is contained in:
parent
bdf3f4d775
commit
8ce73b3f74
@ -69,13 +69,27 @@ func printRespJSON(resp proto.Message) {
|
|||||||
func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
|
func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
if err := f(c); err != nil {
|
if err := f(c); err != nil {
|
||||||
|
s, ok := status.FromError(err)
|
||||||
|
|
||||||
|
// If it's a command for the UnlockerService (like
|
||||||
|
// 'create' or 'unlock') but the wallet is already
|
||||||
|
// unlocked, then these methods aren't recognized any
|
||||||
|
// more because this service is shut down after
|
||||||
|
// successful unlock. That's why the code
|
||||||
|
// 'Unimplemented' means something different for these
|
||||||
|
// two commands.
|
||||||
|
if s.Code() == codes.Unimplemented &&
|
||||||
|
(c.Command.Name == "create" ||
|
||||||
|
c.Command.Name == "unlock") {
|
||||||
|
return fmt.Errorf("Wallet is already unlocked")
|
||||||
|
}
|
||||||
|
|
||||||
// lnd might be active, but not possible to contact
|
// lnd might be active, but not possible to contact
|
||||||
// using RPC if the wallet is encrypted. If we get
|
// using RPC if the wallet is encrypted. If we get
|
||||||
// error code Unimplemented, it means that lnd is
|
// error code Unimplemented, it means that lnd is
|
||||||
// running, but the RPC server is not active yet (only
|
// running, but the RPC server is not active yet (only
|
||||||
// WalletUnlocker server active) and most likely this
|
// WalletUnlocker server active) and most likely this
|
||||||
// is because of an encrypted wallet.
|
// is because of an encrypted wallet.
|
||||||
s, ok := status.FromError(err)
|
|
||||||
if ok && s.Code() == codes.Unimplemented {
|
if ok && s.Code() == codes.Unimplemented {
|
||||||
return fmt.Errorf("Wallet is encrypted. " +
|
return fmt.Errorf("Wallet is encrypted. " +
|
||||||
"Please unlock using 'lncli unlock', " +
|
"Please unlock using 'lncli unlock', " +
|
||||||
|
Loading…
Reference in New Issue
Block a user