Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling Improvement for connection to LND/Wallets Service #252

Closed
lc0des opened this issue Jul 6, 2021 · 1 comment
Closed

Error Handling Improvement for connection to LND/Wallets Service #252

lc0des opened this issue Jul 6, 2021 · 1 comment

Comments

@lc0des
Copy link

lc0des commented Jul 6, 2021

I have spent a real amount of time getting things to work in my personal setup. I think that an improved
error handling in lnbits can spare other people a lot of time. Examplary i will focus only on the Wallet
Connection as this was one major points i struggeled with.
When lnbits is started the method check_funding_source is called. In there the function check_wallet_status. This function receives an error message if something is going wrong.

def check_funding_source(app: QuartTrio) -> None:
    @app.before_serving
    async def check_wallet_status():
        error_message, balance = await WALLET.status()
        if error_message:
            warnings.warn(
                f"  × The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
                RuntimeWarning,
            )

However, it is not stating what exactly is going wrong, as can be seen here:

    async def status(self) -> StatusResponse:
        try:
            async with httpx.AsyncClient(verify=self.cert) as client:
                r = await client.get(
                    f"{self.endpoint}/v1/balance/channels",
                    headers=self.auth,
                )
        except (httpx.ConnectError, httpx.RequestError):
            return StatusResponse(f"Unable to connect to {self.endpoint}.", 0)

        try:
            data = r.json()
            if r.is_error:
                raise Exception
        except Exception:
            return StatusResponse(r.text[:200], 0)

        return StatusResponse(None, int(data["balance"]) * 1000)

The exception catches (httpx.ConnectError, httpx.RequestError) but is not catching the error itself, like
for instance unauthorized, wrong ssl certificated, connection refused, connection timeout to name just a few: currently the code only returns:
return StatusResponse(f"Unable to connect to {self.endpoint}.", 0)

As a result it makes a hard time for someone trying to debug the issue.

Better:
Grab also the error created from the httpx library and return it at least in the daemon print area or better
in a debug logfile.

@dni
Copy link
Member

dni commented Apr 17, 2023

merged

@dni dni closed this as completed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants