Skip to content

Commit 5a882b3

Browse files
committed
feat: add gRPC codes to errors
- new gRPC Codes have been added for better error matching retaining the old text for string matching - first digit indicates server related error - second digit indicates wallet related error - the third and fourth digit error number for the combination Signed-off-by: DarthBenro008 <[email protected]>
1 parent 958119a commit 5a882b3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

rpcperms/interceptor.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"sync"
77

8+
"google.golang.org/grpc/status"
9+
810
"github.com/btcsuite/btclog"
911
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1012
"github.com/lightningnetwork/lnd/lnrpc"
@@ -48,26 +50,26 @@ const (
4850
var (
4951
// ErrWaitingToStart is returned if LND is still wating to start,
5052
// possibly blocked until elected as the leader.
51-
ErrWaitingToStart = fmt.Errorf("waiting to start, RPC services not " +
53+
ErrWaitingToStart = status.Error(1001, "waiting to start, RPC services not "+
5254
"available")
5355

5456
// ErrNoWallet is returned if the wallet does not exist.
55-
ErrNoWallet = fmt.Errorf("wallet not created, create one to enable " +
57+
ErrNoWallet = status.Error(0101, "wallet not created, create one to enable "+
5658
"full RPC access")
5759

5860
// ErrWalletLocked is returned if the wallet is locked and any service
5961
// other than the WalletUnlocker is called.
60-
ErrWalletLocked = fmt.Errorf("wallet locked, unlock it to enable " +
62+
ErrWalletLocked = status.Error(0102, "wallet locked, unlock it to enable "+
6163
"full RPC access")
6264

6365
// ErrWalletUnlocked is returned if the WalletUnlocker service is
6466
// called when the wallet already has been unlocked.
65-
ErrWalletUnlocked = fmt.Errorf("wallet already unlocked, " +
67+
ErrWalletUnlocked = status.Error(0103, "wallet already unlocked, "+
6668
"WalletUnlocker service is no longer available")
6769

6870
// ErrRPCStarting is returned if the wallet has been unlocked but the
6971
// RPC server is not yet ready to accept calls.
70-
ErrRPCStarting = fmt.Errorf("the RPC server is in the process of " +
72+
ErrRPCStarting = status.Error(1002, "the RPC server is in the process of "+
7173
"starting up, but not yet ready to accept calls")
7274

7375
// macaroonWhitelist defines methods that we don't require macaroons to

0 commit comments

Comments
 (0)