Bug: /wallet/balance endpoint lacks exception handling for SQLite errors#2043
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Hi @Scottcjn Bill here, looks like the Skein has pushed 8 files are line-ending artifacts from a Windows build environment. I'll clean that up ASAP. The intended changes are only in node/rewards_implementation_rip200.py and node/tests/test_balance_endpoint.py. Sorry, still working on the Skein! bill0151 |
|
Good security fix addressing #1993 — wrapping the Before we can merge:
Once fixed: 15 RTC approved. Tip: |
b7c4bca to
c4bd19e
Compare
|
Hello again @Scottcjn — pushed the fix: constants moved outside the import block and the diff is now down to the 2 intended files only. |
zhuzhushiwojia
left a comment
There was a problem hiding this comment.
Good fix for the database error handling issue. A few observations:
Positive:
- Properly wraps database operations in try-except blocks
- Returns appropriate HTTP status codes (503 for lock, 500 for general errors)
- Uses constant definitions for error messages (good practice)
Suggestions:
- Consider adding logging at a more verbose level (e.g., debug) for production debugging
- The error messages could include a correlation ID for easier debugging in distributed systems
- Consider adding a circuit breaker pattern for repeated database failures
Minor nit:
- The constants
RTC_DECIMAL_PRECISION,DATABASE_LOCKED_ERROR_MESSAGE,UNEXPECTED_DATABASE_ERROR_MESSAGEcould be defined alongside other constants at the top of the file, not after thejsonifyfunction.
Overall: ✅ Approve - addresses the reported bug correctly.
|
@zhuzhushiwojia I can see your post is for another bounty, but wanted to thank you for taking the time to share your thoughts and let you know I'll take note of them. All feedback is welcome - especially when it's mutually beneficial for the project. |
FILE: node/rewards_implementation_rip200.py
NEW ADDITION (insert after line ~65):
REASON: These constants improve code readability and maintainability for API error messages and financial precision.
FILE: node/rewards_implementation_rip200.py
FUNCTION: get_balance (line ~189 in current source)
BEFORE (existing code — shown for context, do NOT include in PR):
AFTER (your replacement — this IS the PR content):
REASON: This change adds robust error handling for database operations, preventing unhandled 500 errors and providing specific responses for operational issues like database locks, and ensures RTC amounts are rounded for consistent precision.
REASON: This new test suite thoroughly validates the
/wallet/balanceendpoint, covering success cases, missing/invalid parameters, and critical database error scenarios, ensuring the robustness and correctness of the API.