Skip to content

Error handling#976

Closed
R27-pixel wants to merge 2 commits into
getfloresta:masterfrom
R27-pixel:error_handling
Closed

Error handling#976
R27-pixel wants to merge 2 commits into
getfloresta:masterfrom
R27-pixel:error_handling

Conversation

@R27-pixel
Copy link
Copy Markdown

Description and Notes

This PR replaces panicking .unwrap(), .expect(), and assert! calls in floresta-watch-only with proper error propagation to prevent production aborts on recoverable failures.

A new WatchOnlyError::InsufficientBalance { address_balance, debit_value } variant was added to handle balance inconsistencies safely instead of panicking.

Changes made

  • AddressCacheInner::new() now returns Result and propagates database failures from database.load() and database.save_stats() using ?
  • cache_transaction() now returns Result and propagates save_transaction() failures instead of using .expect()
  • block_process() now returns Result and propagates errors from cache_transaction() using ?
  • BlockConsumer::on_block() logs errors using tracing::error! instead of panicking
  • save_non_mempool_tx() now returns Result and replaces assert!(value <= address.balance) with WatchOnlyError::InsufficientBalance
  • AddressCache::new() now returns Result and propagates constructor errors properly
  • Updated other affected files to support the Result-based flow

Tests

Added test_insufficient_balance_error to verify that debiting more than an address’s recorded balance returns WatchOnlyError::InsufficientBalance instead of panicking.


How to verify the changes you have done?

Run:

cargo test
cargo test test_insufficient_balance_error
cargo fmt
cargo clippy

@Davidson-Souza
Copy link
Copy Markdown
Member

This seems to be a duplicate of #931

@R27-pixel
Copy link
Copy Markdown
Author

This seems to be a duplicate of #931
Thanks for pointing that out. I worked on this mainly as part of my proposal/competency task and for learning the codebase, so I didn’t check the other open PRs closely ,I should have done that. I’ll review the existing PR and align accordingly.
I'll update the pr , thanks !!.

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

Successfully merging this pull request may close these issues.

3 participants