Skip to content

Commit 193d2a6

Browse files
authored
Merge pull request #9649 from guggero/cmd-fix
cmd: fix incorrect error code
2 parents f48e509 + 04533e9 commit 193d2a6

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cmd/commands/commands.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/lightningnetwork/lnd/lnwire"
2525
"github.com/lightningnetwork/lnd/routing"
2626
"github.com/lightningnetwork/lnd/routing/route"
27+
"github.com/lightningnetwork/lnd/rpcperms"
2728
"github.com/lightningnetwork/lnd/signal"
2829
"github.com/urfave/cli"
2930
"golang.org/x/term"
@@ -258,7 +259,7 @@ func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
258259
return nil
259260
}
260261

261-
// Try to parse the Status representatio from this error.
262+
// Try to parse the Status representation from this error.
262263
s, ok := status.FromError(err)
263264

264265
// If this cannot be represented by a Status, exit early.
@@ -270,21 +271,22 @@ func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
270271
// 'unlock') but the wallet is already unlocked, then these
271272
// methods aren't recognized any more because this service is
272273
// shut down after successful unlock.
273-
if s.Code() == codes.Unknown &&
274-
(c.Command.Name == "create" ||
275-
c.Command.Name == "unlock" ||
276-
c.Command.Name == "changepassword" ||
277-
c.Command.Name == "createwatchonly") {
274+
if s.Code() == codes.Unknown && strings.Contains(
275+
s.Message(), rpcperms.ErrWalletUnlocked.Error(),
276+
) && (c.Command.Name == "create" ||
277+
c.Command.Name == "unlock" ||
278+
c.Command.Name == "changepassword" ||
279+
c.Command.Name == "createwatchonly") {
278280

279281
return errors.New("wallet is already unlocked")
280282
}
281283

282284
// lnd might be active, but not possible to contact using RPC if
283-
// the wallet is encrypted. If we get error code Unknown, it
284-
// means that lnd is running, but the RPC server is not active
285-
// yet (only WalletUnlocker server active) and most likely this
286-
// is because of an encrypted wallet.
287-
if s.Code() == codes.Unknown {
285+
// the wallet is encrypted.
286+
if s.Code() == codes.Unknown && strings.Contains(
287+
s.Message(), rpcperms.ErrWalletLocked.Error(),
288+
) {
289+
288290
return errors.New("wallet is encrypted - please " +
289291
"unlock using 'lncli unlock', or set " +
290292
"password using 'lncli create' if this is " +

0 commit comments

Comments
 (0)