Skip to content

fix(mint): catch backend errors during startup status check - #1124

Open
KvngMikey wants to merge 2 commits into
cashubtc:mainfrom
KvngMikey:fix/friendly-backend-startup-error
Open

fix(mint): catch backend errors during startup status check#1124
KvngMikey wants to merge 2 commits into
cashubtc:mainfrom
KvngMikey:fix/friendly-backend-startup-error

Conversation

@KvngMikey

@KvngMikey KvngMikey commented Aug 18, 2026

Copy link
Copy Markdown
Member

Closes #518.

Summary

Ledger._check_backends() already renders an unhealthy backend into a readable message and exits cleanly — but only when the backend returns a StatusResponse carrying error_message. Backends that raise instead bypass that path entirely: the exception propagates through startup_ledger() to start_mint() to the FastAPI lifespan, and the operator gets the raw stack trace the issue describes.

Reproduced on current main by pointing MINT_BACKEND_BOLT11_SAT=CLNRestWallet at an unreachable host:

INFO | Using CLNRestWallet backend for method: 'bolt11' and unit: 'sat'
httpx.ConnectError: All connection attempts failed

Changes

Rather than patch each backend, this normalises a raised exception into the StatusResponse contract at the single point where startup consumes it.

Reporting failure two different ways (return vs. raise) is what let the backends drift apart in the first place. Handling both where they are read means a backend added later is covered without its author having to know this rule exists, which is what makes this a fix rather than four patches.

The exception type is kept in the operator-facing message so the cause stays identifiable, and the full traceback is logged at DEBUG for maintainers diagnosing an unexpected failure rather than an unreachable host.

Result

ERROR | The backend for CLNRestWallet isn't working properly:
'ConnectError: All connection attempts failed'

`_check_backends()` already renders an unhealthy backend into a readable
message and exits cleanly, but only when the backend *returns* a
`StatusResponse` carrying `error_message`. Backends that *raise* instead
bypass that path entirely: the exception propagates through
`startup_ledger()` -> `start_mint()` -> the FastAPI lifespan and the
operator gets a raw stack trace.
Copilot AI lite review requested due to automatic review settings August 18, 2026 16:38
@github-project-automation github-project-automation Bot moved this to Backlog in nutshell Aug 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves mint startup robustness by ensuring backend status-check failures raised as exceptions are converted into the existing StatusResponse error contract, preventing noisy stack traces from leaking to operators during FastAPI lifespan startup.

Changes:

  • Wraps backend .status() calls during Ledger._check_backends() in a try/except to normalize raised exceptions into a StatusResponse(error_message=...).
  • Logs the full traceback at DEBUG while keeping the operator-facing failure message concise and consistent.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cashu/mint/ledger.py
Comment thread cashu/mint/ledger.py
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.66%. Comparing base (6eed7b2) to head (6cb7f2b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1124      +/-   ##
==========================================
+ Coverage   74.59%   74.66%   +0.07%     
==========================================
  Files         113      113              
  Lines       12760    12765       +5     
==========================================
+ Hits         9518     9531      +13     
+ Misses       3242     3234       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Mint] Return more human-friendly error if mint can't reach backend during startup

2 participants