Merge pull request #9649 from guggero/cmd-fix

cmd: fix incorrect error code
This commit is contained in:
Oliver Gugger authored and GitHub committed 2025-03-26 13:19:43 -06:00
commit 193d2a6581
1 file changed
+13 -11
+13 -11
View File
@@ -24,6 +24,7 @@ import (
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal" "github.com/lightningnetwork/lnd/signal"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/term" "golang.org/x/term"
@@ -258,7 +259,7 @@ func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
return nil return nil
} }
// Try to parse the Status representatio from this error. // Try to parse the Status representation from this error.
s, ok := status.FromError(err) s, ok := status.FromError(err)
// If this cannot be represented by a Status, exit early. // 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 {
// 'unlock') but the wallet is already unlocked, then these // 'unlock') but the wallet is already unlocked, then these
// methods aren't recognized any more because this service is // methods aren't recognized any more because this service is
// shut down after successful unlock. // shut down after successful unlock.
if s.Code() == codes.Unknown && if s.Code() == codes.Unknown && strings.Contains(
(c.Command.Name == "create" || s.Message(), rpcperms.ErrWalletUnlocked.Error(),
c.Command.Name == "unlock" || ) && (c.Command.Name == "create" ||
c.Command.Name == "changepassword" || c.Command.Name == "unlock" ||
c.Command.Name == "createwatchonly") { c.Command.Name == "changepassword" ||
c.Command.Name == "createwatchonly") {
return errors.New("wallet is already unlocked") return errors.New("wallet is already unlocked")
} }
// lnd might be active, but not possible to contact using RPC if // lnd might be active, but not possible to contact using RPC if
// the wallet is encrypted. If we get error code Unknown, it // the wallet is encrypted.
// means that lnd is running, but the RPC server is not active if s.Code() == codes.Unknown && strings.Contains(
// yet (only WalletUnlocker server active) and most likely this s.Message(), rpcperms.ErrWalletLocked.Error(),
// is because of an encrypted wallet. ) {
if s.Code() == codes.Unknown {
return errors.New("wallet is encrypted - please " + return errors.New("wallet is encrypted - please " +
"unlock using 'lncli unlock', or set " + "unlock using 'lncli unlock', or set " +
"password using 'lncli create' if this is " + "password using 'lncli create' if this is " +