fix(mint): catch backend errors during startup status check - #1124
Open
KvngMikey wants to merge 2 commits into
Open
fix(mint): catch backend errors during startup status check#1124KvngMikey wants to merge 2 commits into
KvngMikey wants to merge 2 commits into
Conversation
`_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.
There was a problem hiding this comment.
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 duringLedger._check_backends()in atry/exceptto normalize raised exceptions into aStatusResponse(error_message=...). - Logs the full traceback at
DEBUGwhile 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #518.
Summary
Ledger._check_backends()already renders an unhealthy backend into a readable message and exits cleanly — but only when the backend returns aStatusResponsecarryingerror_message. Backends that raise instead bypass that path entirely: the exception propagates throughstartup_ledger()tostart_mint()to the FastAPI lifespan, and the operator gets the raw stack trace the issue describes.Reproduced on current
mainby pointingMINT_BACKEND_BOLT11_SAT=CLNRestWalletat an unreachable host:Changes
Rather than patch each backend, this normalises a raised exception into the
StatusResponsecontract 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
DEBUGfor 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'