esplora: don't panic in raw_to_num on bad response - #102
Merged
Conversation
raw_to_num used .expect() for both the UTF-8 decode and the i64 parse, crashing the bitcoin backend if the esplora endpoint ever returns a non-numeric body (HTML error page, captive portal, malformed proxy response, etc.). Switch the function to return Result<i64, PluginError> and propagate a structured error including the offending body, so the recovery strategy can retry instead of taking the daemon down. Trim whitespace before parsing for safety, and log the parsed input at debug level for diagnostics. Update the two callers in sync_block_by_height and sync_chain_info from .map() to .and_then() to match the new signature. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
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.
Summary
raw_to_numpreviously.expect()-ed both the UTF-8 decode and thei64::parse, which crashed the bitcoin backend whenever an esplora endpoint returned anything non-numeric (HTML error page, captive portal interstitial, mangled body through a proxy, etc.). The panic message was"impossible parse a string into a i64: ParseIntError { kind: InvalidDigit }"and took the whole node down.Result<i64, PluginError>and surface the offending bytes in the error, soRecoveryStrategy::applycan retry instead of crashing..map(|raw| raw_to_num(&raw))callers insync_block_by_heightandsync_chain_infoto.and_then(...)to match the new signature.Test plan
cargo build --release -p folgore-esplora -p folgore_pluginsucceeds with no warnings.raw_to_num input: "..." (len=N)debug logs show clean integer bodies on each/blocks/tip/heightpoll.getinforeturns healthy state and the daemon resumes block sync after the patch.🤖 Generated with Claude Code
Fixes #100