Refactor token metadata fetch error handling#2263
Conversation
WalkthroughThis PR refactors module organization by moving address collection functions from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (3)crates/*/{src,tests,benches,examples}/**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
crates/**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (13)📓 Common learnings📚 Learning: 2025-10-14T07:51:55.148ZApplied to files:
📚 Learning: 2025-10-06T14:41:41.909ZApplied to files:
📚 Learning: 2025-10-18T10:38:41.273ZApplied to files:
📚 Learning: 2025-10-13T12:57:05.900ZApplied to files:
📚 Learning: 2025-10-06T14:39:36.425ZApplied to files:
📚 Learning: 2025-10-06T13:03:35.337ZApplied to files:
📚 Learning: 2025-07-15T08:01:38.534ZApplied to files:
📚 Learning: 2025-08-01T07:44:53.910ZApplied to files:
📚 Learning: 2025-08-02T02:34:32.237ZApplied to files:
📚 Learning: 2025-10-06T11:28:30.692ZApplied to files:
📚 Learning: 2025-06-17T16:32:04.554ZApplied to files:
📚 Learning: 2025-07-30T07:41:39.271ZApplied to files:
🧬 Code graph analysis (3)crates/common/src/local_db/sync.rs (1)
crates/common/src/local_db/mod.rs (4)
crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
🔇 Additional comments (4)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
crates/cli/src/commands/local_db/sync/runner/mod.rs(1 hunks)crates/cli/src/commands/local_db/sync/token.rs(1 hunks)crates/common/src/local_db/mod.rs(3 hunks)crates/common/src/local_db/sync.rs(1 hunks)crates/common/src/local_db/token_fetch.rs(3 hunks)crates/common/src/raindex_client/local_db/mod.rs(1 hunks)crates/common/src/raindex_client/mod.rs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-06T11:13:29.956Z
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2123
File: crates/common/src/raindex_client/local_db/mod.rs:23-29
Timestamp: 2025-10-06T11:13:29.956Z
Learning: In `crates/common/src/raindex_client/local_db/mod.rs`, the `Default` implementation for `LocalDb` that creates an RPC client pointing to `http://localhost:4444` is acceptable because the RPC client must be explicitly configured before actual usage in production scenarios.
Applied to files:
crates/common/src/raindex_client/local_db/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
- GitHub Check: git-clean
- GitHub Check: test
- GitHub Check: test
- GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
- GitHub Check: test
- GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
- GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
- GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
- GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
- GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
- GitHub Check: build-tauri (ubuntu-22.04, true)
- GitHub Check: Deploy-Docs-Preview
- GitHub Check: Deploy-Preview-Push
🔇 Additional comments (8)
crates/common/src/local_db/sync.rs (1)
2-2: Switched to address_collectors module.Consistent with the refactor; usage below remains unchanged. LGTM.
crates/common/src/raindex_client/mod.rs (2)
315-315: Box LocalDbError in RaindexError is appropriate.Improves size/ABI and preserves chaining; transparent #[from] on Box is correct. LGTM.
328-332: Update error message at line 442 to useto_readable_msg()The
From<LocalDbError>implementation is correctly structured with automatic boxing. However, update the error message to match the pattern used elsewhere in the codebase:RaindexError::LocalDbError(err) => { - format!("There was an error with the local database: {err}") + format!("There was an error with the local database: {}", err.to_readable_msg()) }The
to_readable_msg()method exists onLocalDbErrorand provides more detailed error context than the defaultDisplayimplementation.⛔ Skipped due to learnings
Learnt from: brusherru PR: rainlanguage/rain.orderbook#2036 File: crates/js_api/src/filters/errors.rs:39-46 Timestamp: 2025-08-01T07:35:13.418Z Learning: In the Rain Orderbook project's PersistentFilterStoreError (crates/js_api/src/filters/errors.rs), the Display implementation already provides user-friendly error messages, so using err.to_string() for both msg and readable_msg in the WasmEncodedError conversion is appropriate and doesn't require separate readable message handling.crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
19-19: Collector import re-pointed; LGTM.Aligns with module rename; no behavior change.
crates/common/src/local_db/mod.rs (3)
74-81: New structured error variant is solid.Captures address, attempt count, and chained source. LGTM.
131-139: Readable message includes source; good.Works well with the new variant. Coordinate with RaindexError to call
to_readable_msg()so this detail isn’t lost (see related comment in raindex_client/mod.rs).⛔ Skipped due to learnings
Learnt from: brusherru PR: rainlanguage/rain.orderbook#2036 File: crates/js_api/src/filters/errors.rs:39-46 Timestamp: 2025-08-01T07:35:13.418Z Learning: In the Rain Orderbook project's PersistentFilterStoreError (crates/js_api/src/filters/errors.rs), the Display implementation already provides user-friendly error messages, so using err.to_string() for both msg and readable_msg in the WasmEncodedError conversion is appropriate and doesn't require separate readable message handling.
1-1: Address_collectors module properly integrated; migration from tokens completeVerification confirms no stale re-exports or code referencing the removed
local_db::tokensmodule. The newaddress_collectorsexport is correctly utilized across sync operations. Thetokensmodule found insettings/remoteis unrelated (handles token metadata lists, not local_db functionality).crates/cli/src/commands/local_db/sync/token.rs (1)
5-5: Import path update to address_collectors confirmed correct.Verification completed: no stale
local_db::tokensimports remain, new path is properly resolved, and all function usages are consistent across the codebase. The module reorganization is sound.
| Err(RetryError::Operation(err)) => { | ||
| Err(LocalDbError::TokenMetadataFetchFailed { | ||
| address: addr, | ||
| attempts: max_attempts, | ||
| source: Box::new(err), | ||
| }) | ||
| } |
There was a problem hiding this comment.
“attempts” reports configured max, not actual tries. Track real attempt count.
If the first failure is non‑retryable, this records max_attempts instead of 1, misleading diagnostics.
Apply this change to report actual attempts:
- Err(RetryError::Operation(err)) => {
- Err(LocalDbError::TokenMetadataFetchFailed {
- address: addr,
- attempts: max_attempts,
- source: Box::new(err),
- })
- }
+ Err(RetryError::Operation(err)) => {
+ let attempts = attempt_counter.load(std::sync::atomic::Ordering::Relaxed);
+ Err(LocalDbError::TokenMetadataFetchFailed {
+ address: addr,
+ attempts,
+ source: Box::new(err),
+ })
+ }Additional changes needed outside this hunk:
@@
- futures::stream::iter(missing_addrs.into_iter().map(|addr| {
+ futures::stream::iter(missing_addrs.into_iter().map(|addr| {
let rpcs = rpcs.clone();
async move {
let erc20 = ERC20::new(rpcs, addr);
+ let attempt_counter = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
let result = retry_with_backoff(
|| {
- let erc20 = erc20.clone();
- async move { erc20.token_info(None).await }
+ let erc20 = erc20.clone();
+ let attempt_counter = attempt_counter.clone();
+ async move {
+ attempt_counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+ erc20.token_info(None).await
+ }
},And add imports at the top of this file:
+use std::sync::{Arc};
+use std::sync::atomic::{AtomicUsize, Ordering};Committable suggestion skipped: line range outside the PR's diff.
| pub fn get_local_db_client(&self, chain_id: u32) -> Result<LocalDb, RaindexError> { | ||
| let rpcs = self.get_rpc_urls_for_chain(chain_id)?; | ||
| LocalDb::new_with_regular_rpcs(rpcs).map_err(RaindexError::LocalDbError) | ||
| LocalDb::new_with_regular_rpcs(rpcs).map_err(RaindexError::from) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Use Into::into for brevity.
Current code is fine; this is a tiny readability tweak.
- LocalDb::new_with_regular_rpcs(rpcs).map_err(RaindexError::from)
+ LocalDb::new_with_regular_rpcs(rpcs).map_err(Into::into)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LocalDb::new_with_regular_rpcs(rpcs).map_err(RaindexError::from) | |
| LocalDb::new_with_regular_rpcs(rpcs).map_err(Into::into) |
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/local_db/mod.rs around line 24, replace the
explicit map_err(RaindexError::from) call with map_err(Into::into) for brevity;
update the map_err argument to use Into::into so the error conversion is
performed via the Into trait instead of calling RaindexError::from directly.
There was a problem hiding this comment.
@findolor, understood! I'll keep the explicit RaindexError::from approach as you prefer.
(\__/)
(•ᴗ•)
/>📋 Noted!
🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2123
File: crates/common/src/raindex_client/local_db/mod.rs:23-29
Timestamp: 2025-10-06T11:13:29.956Z
Learning: In `crates/common/src/raindex_client/local_db/mod.rs`, the `Default` implementation for `LocalDb` that creates an RPC client pointing to `http://localhost:4444` is acceptable because the RPC client must be explicitly configured before actual usage in production scenarios.
|
@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment: S/M/L PR Classification Guidelines:This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed. Small (S)Characteristics:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
|
Tip For best results, initiate chat on the files or code changes. SIZE=M 🧠 Learnings used |
Motivation
See issues:
tokens.rsto Reflect Address Collection Responsibilities #2230Solution
tokens.rstoaddress_collector.rsChecks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit