From 2445c00c7e61a6f9cfd99fdd91b80dbc8ee6513c Mon Sep 17 00:00:00 2001
From: Jack Robison <jackrobison@lbry.io>
Date: Tue, 17 Aug 2021 11:14:43 -0400
Subject: [PATCH] raise WalletNotLoadedError in get_wallet_or_error instead of
 ValueError

---
 lbry/error/README.md   | 1 +
 lbry/error/__init__.py | 7 +++++++
 lbry/wallet/manager.py | 4 ++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lbry/error/README.md b/lbry/error/README.md
index 352c903f4..cc251a55a 100644
--- a/lbry/error/README.md
+++ b/lbry/error/README.md
@@ -61,6 +61,7 @@ Code | Name | Message
 431 | ServerPaymentInvalidAddress | Invalid address from wallet server: '{address}' - skipping payment round.
 432 | ServerPaymentWalletLocked | Cannot spend funds with locked wallet, skipping payment round.
 433 | ServerPaymentFeeAboveMaxAllowed | Daily server fee of {daily_fee} exceeds maximum configured of {max_fee} LBC.
+434 | WalletNotLoaded | Wallet {wallet_id} is not loaded.
 **5xx** | Blob | **Blobs**
 500 | BlobNotFound | Blob not found.
 501 | BlobPermissionDenied | Permission denied to read blob.
diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py
index 9b66a20f2..e5e819901 100644
--- a/lbry/error/__init__.py
+++ b/lbry/error/__init__.py
@@ -271,6 +271,13 @@ class ServerPaymentFeeAboveMaxAllowedError(WalletError):
         super().__init__(f"Daily server fee of {daily_fee} exceeds maximum configured of {max_fee} LBC.")
 
 
+class WalletNotLoadedError(WalletError):
+
+    def __init__(self, wallet_id):
+        self.wallet_id = wallet_id
+        super().__init__(f"Wallet {wallet_id} is not loaded.")
+
+
 class BlobError(BaseError):
     """
     **Blobs**
diff --git a/lbry/wallet/manager.py b/lbry/wallet/manager.py
index 6228159b6..2c7d858ad 100644
--- a/lbry/wallet/manager.py
+++ b/lbry/wallet/manager.py
@@ -7,7 +7,7 @@ from binascii import unhexlify
 from decimal import Decimal
 from typing import List, Type, MutableSequence, MutableMapping, Optional
 
-from lbry.error import KeyFeeAboveMaxAllowedError
+from lbry.error import KeyFeeAboveMaxAllowedError, WalletNotLoadedError
 from lbry.conf import Config, NOT_SET
 
 from .dewies import dewies_to_lbc
@@ -95,7 +95,7 @@ class WalletManager:
         for wallet in self.wallets:
             if wallet.id == wallet_id:
                 return wallet
-        raise ValueError(f"Couldn't find wallet: {wallet_id}.")
+        raise WalletNotLoadedError(wallet_id)
 
     @staticmethod
     def get_balance(wallet):