From 2d4c9f349b2c68e9324c989a59b7e65ffef3bc37 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 21 Jul 2023 09:50:50 +0200 Subject: [PATCH] Wallets: Catch errors during cleanup (#1829) * jetz aba * catch RuntimeError --- lnbits/wallets/eclair.py | 5 ++++- lnbits/wallets/lnbits.py | 5 ++++- lnbits/wallets/lndrest.py | 5 ++++- lnbits/wallets/lnpay.py | 5 ++++- lnbits/wallets/lntips.py | 5 ++++- lnbits/wallets/opennode.py | 5 ++++- lnbits/wallets/spark.py | 5 ++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lnbits/wallets/eclair.py b/lnbits/wallets/eclair.py index da40192f..bf307e23 100644 --- a/lnbits/wallets/eclair.py +++ b/lnbits/wallets/eclair.py @@ -44,7 +44,10 @@ class EclairWallet(Wallet): self.client = httpx.AsyncClient(base_url=self.url, headers=self.auth) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: r = await self.client.post("/globalbalance", timeout=5) diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index f91ef6de..c951e385 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -32,7 +32,10 @@ class LNbitsWallet(Wallet): self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.key) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: try: diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index 99ceaf54..4b00dbbc 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -69,7 +69,10 @@ class LndRestWallet(Wallet): ) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: try: diff --git a/lnbits/wallets/lnpay.py b/lnbits/wallets/lnpay.py index af60e10b..b2394d57 100644 --- a/lnbits/wallets/lnpay.py +++ b/lnbits/wallets/lnpay.py @@ -35,7 +35,10 @@ class LNPayWallet(Wallet): self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: url = f"/wallet/{self.wallet_key}" diff --git a/lnbits/wallets/lntips.py b/lnbits/wallets/lntips.py index 4ba07c78..a4c935fe 100644 --- a/lnbits/wallets/lntips.py +++ b/lnbits/wallets/lntips.py @@ -33,7 +33,10 @@ class LnTipsWallet(Wallet): self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: r = await self.client.get("/api/v1/balance", timeout=40) diff --git a/lnbits/wallets/opennode.py b/lnbits/wallets/opennode.py index c75b57ab..8053da88 100644 --- a/lnbits/wallets/opennode.py +++ b/lnbits/wallets/opennode.py @@ -37,7 +37,10 @@ class OpenNodeWallet(Wallet): self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") async def status(self) -> StatusResponse: try: diff --git a/lnbits/wallets/spark.py b/lnbits/wallets/spark.py index 4e02693c..17410a1b 100644 --- a/lnbits/wallets/spark.py +++ b/lnbits/wallets/spark.py @@ -37,7 +37,10 @@ class SparkWallet(Wallet): ) async def cleanup(self): - await self.client.aclose() + try: + await self.client.aclose() + except RuntimeError as e: + logger.warning(f"Error closing wallet connection: {e}") def __getattr__(self, key): async def call(*args, **kwargs):