Skip to content

Refactor token metadata fetch error handling#2263

Merged
findolor merged 5 commits intomainfrom
local-db-token-metadata-err
Oct 31, 2025
Merged

Refactor token metadata fetch error handling#2263
findolor merged 5 commits intomainfrom
local-db-token-metadata-err

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented Oct 23, 2025

Motivation

See issues:

Solution

  • Rename tokens.rs to address_collector.rs
  • Update token metadata logic to return proper errors
  • Update tests

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Refactor
    • Internal code reorganization to improve system architecture and maintainability. Enhanced error handling mechanisms to better manage edge cases and provide more reliable operation.

@findolor findolor added this to the LocalDB Implementation milestone Oct 23, 2025
@findolor findolor requested review from 0xgleb and hardyjosh October 23, 2025 06:25
@findolor findolor self-assigned this Oct 23, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 23, 2025

Walkthrough

This PR refactors module organization by moving address collection functions from tokens to a new address_collectors module within local_db. It updates all corresponding import paths, adds a new TokenMetadataFetchFailed error variant, and modifies error wrapping to use Box<LocalDbError> in RaindexError.

Changes

Cohort / File(s) Change Summary
Import path updates
crates/cli/src/commands/local_db/sync/runner/mod.rs, crates/cli/src/commands/local_db/sync/token.rs, crates/common/src/local_db/sync.rs
Updated imports for collect_store_addresses and collect_token_addresses from rain_orderbook_common::local_db::tokens to rain_orderbook_common::local_db::address_collectors
Module reorganization
crates/common/src/local_db/mod.rs
Added public module address_collectors, removed public module tokens, added TokenError import alias
Error surface expansion
crates/common/src/local_db/mod.rs
Added TokenMetadataFetchFailed variant to LocalDbError with address, attempts, and boxed source fields; updated to_readable_msg formatting
Error wrapping refactoring
crates/common/src/raindex_client/mod.rs, crates/common/src/raindex_client/local_db/mod.rs
Changed RaindexError::LocalDbError to wrap Box<LocalDbError>; introduced From<LocalDbError> conversion trait; updated error mapping in get_local_db_client

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Multiple repetitive import updates across CLI and common crates (low individual effort)
  • Module reorganization and public API surface changes require verification of completeness
  • New error variant logic and its integration into to_readable_msg method
  • Box wrapping semantics change for LocalDbError needs attention to ensure proper error propagation
  • Verify all usages of moved functions are updated consistently

Possibly related PRs

Suggested reviewers

  • hardyjosh
  • 0xgleb

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Refactor token metadata fetch error handling" directly corresponds to the core objective of the changes. The PR introduces a new TokenMetadataFetchFailed error variant in LocalDbError, adds error formatting logic, and reorganizes modules to support proper error propagation for token metadata fetching—all of which align with the PR's stated motivation to address error handling issues. The title is concise, specific, and clearly communicates the primary change without being vague or generic. While the PR also involves module reorganization (renaming tokens to address_collectors), this appears to be an implementation detail supporting the main error handling refactoring.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch local-db-token-metadata-err

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c94d71e and 23fa7cd.

📒 Files selected for processing (3)
  • crates/cli/src/commands/local_db/sync/runner/mod.rs (1 hunks)
  • crates/common/src/local_db/mod.rs (3 hunks)
  • crates/common/src/local_db/sync.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
crates/*/{src,tests,benches,examples}/**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Rust code must pass clippy with all warnings denied (cargo clippy --workspace --all-targets --all-features -D warnings)

Files:

  • crates/common/src/local_db/sync.rs
  • crates/common/src/local_db/mod.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
crates/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Rust code lives in the workspace under crates/* (e.g., cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests)

Files:

  • crates/common/src/local_db/sync.rs
  • crates/common/src/local_db/mod.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Format Rust with nix develop -c cargo fmt --all
Lint Rust with nix develop -c rainix-rs-static (preconfigured flags)
Use snake_case for Rust crates/modules and PascalCase for types

Files:

  • crates/common/src/local_db/sync.rs
  • crates/common/src/local_db/mod.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
🧠 Learnings (13)
📓 Common learnings
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.717Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2117
File: crates/js_api/src/gui/select_tokens.rs:421-424
Timestamp: 2025-09-02T08:04:34.729Z
Learning: User findolor in the rainlanguage/rain.orderbook codebase prefers not to change test code when tests are already passing, even if there appear to be type mismatches or potential issues. Working tests should be left alone unless there are actual errors.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/fuzz/mod.rs:64-64
Timestamp: 2025-07-04T09:02:57.301Z
Learning: In rainlanguage/rain.orderbook, user findolor prefers to limit type consistency changes to only the parts directly related to the current work scope. For example, when updating chain_id fields from u64 to u32 in fuzz-related code, unrelated files like tauri-app wallet commands can remain as u64 if they serve different purposes and aren't part of the current changes.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: tauri-app/src/routes/orders/[chainId]-[orderbook]-[orderHash]/+page.svelte:76-78
Timestamp: 2025-07-31T19:03:56.594Z
Learning: In the rainlanguage/rain.orderbook project, when the Tauri app has issues preventing proper testing, the team prefers to defer Tauri-specific implementations to separate PRs rather than including untested code, especially for financial operations like withdrawals.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2163
File: packages/webapp/src/routes/deploy/[orderName]/[deploymentKey]/fullDeployment.test.ts:214-215
Timestamp: 2025-09-24T11:06:36.718Z
Learning: In the rain.orderbook project, findolor is comfortable with public token addresses in test files even when they trigger Gitleaks warnings, as these are legitimate public addresses and not actual secrets requiring annotation or refactoring.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1994
File: crates/common/src/raindex_client/vaults.rs:59-59
Timestamp: 2025-07-16T05:52:05.576Z
Learning: User findolor prefers to handle documentation updates for getter methods in batch via dedicated PRs rather than addressing them individually during feature development, as mentioned for the formatted amount string fields in crates/common/src/raindex_client/vaults.rs.
📚 Learning: 2025-10-14T07:51:55.148Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2202
File: crates/common/src/raindex_client/local_db/sync.rs:33-34
Timestamp: 2025-10-14T07:51:55.148Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the hard-coded `DEFAULT_SYNC_CHAIN_ID` constant (set to `SUPPORTED_LOCAL_DB_CHAINS[0]`) will be replaced with proper chain ID handling in downstream PRs as part of the multi-network/orderbook implementation.

Applied to files:

  • crates/common/src/local_db/sync.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-06T14:41:41.909Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2159
File: crates/cli/src/commands/local_db/sync/runner/mod.rs:52-113
Timestamp: 2025-10-06T14:41:41.909Z
Learning: The local DB sync CLI command (crates/cli/src/commands/local_db/sync/) is designed for CI-only usage, and simple println! statements are preferred over structured logging for status messages.

Applied to files:

  • crates/common/src/local_db/sync.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-18T10:38:41.273Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2237
File: crates/common/src/raindex_client/local_db/sync.rs:79-89
Timestamp: 2025-10-18T10:38:41.273Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the sync_database method currently only supports indexing a single orderbook per chain ID, which is why `.first()` is used to select the orderbook configuration. Multi-orderbook support per chain ID is planned for future PRs.

Applied to files:

  • crates/common/src/local_db/sync.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-13T12:57:05.900Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2198
File: crates/common/src/raindex_client/local_db/query/fetch_store_addresses/mod.rs:7-8
Timestamp: 2025-10-13T12:57:05.900Z
Learning: In the rain.orderbook repository, using unqualified serde helper names (e.g., `#[serde(with = "serde_address")]`) that rely on glob imports is acceptable and does not need to be changed to fully qualified paths.

Applied to files:

  • crates/common/src/local_db/sync.rs
  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-06T14:39:36.425Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2159
File: crates/cli/src/commands/local_db/sync/cli.rs:37-78
Timestamp: 2025-10-06T14:39:36.425Z
Learning: In the SyncLocalDb CLI command (crates/cli/src/commands/local_db/sync/cli.rs), block range validation (e.g., start_block <= end_block) is handled internally by the sync runner, not at the CLI entry point.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-06T13:03:35.337Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2146
File: crates/cli/src/commands/local_db/README.md:22-106
Timestamp: 2025-10-06T13:03:35.337Z
Learning: In the rain.orderbook repository, `cargo run` commands work without the `--` separator (e.g., `cargo run local-db fetch-events` works directly). Do not suggest adding `--` before CLI arguments in cargo run examples for this repository.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-07-15T08:01:38.534Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1994
File: crates/common/src/raindex_client/vaults.rs:282-292
Timestamp: 2025-07-15T08:01:38.534Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor prefers to avoid concurrency optimizations like using `futures::future::try_join_all` for parallel processing of balance changes, considering such optimizations "not that critical at the moment" when the performance impact is minimal.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-08-01T07:44:53.910Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:319-336
Timestamp: 2025-08-01T07:44:53.910Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore (crates/js_api/src/filters/raindex_filter_store.rs), the team chose a simplified monolithic approach with hard-coded keys and default auto-save behavior over configurable stores. The update_vaults method intentionally auto-saves to both localStorage and URL after each update as the default behavior, following a design evolution from a previous configurable approach.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-08-02T02:34:32.237Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-10-06T11:28:30.692Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql:6-7
Timestamp: 2025-10-06T11:28:30.692Z
Learning: In `crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql`, the orderbook_address is currently hardcoded to '0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB' because the system only supports a single orderbook at the moment. Multiorderbook logic is not yet implemented and will be added in the future.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-06-17T16:32:04.554Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1903
File: crates/js_api/src/gui/order_operations.rs:124-134
Timestamp: 2025-06-17T16:32:04.554Z
Learning: In the rain.orderbook codebase, RPC lists are typically small (2 items maximum), so performance optimizations around cloning and converting small Vec<Url> collections are generally unnecessary.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
📚 Learning: 2025-07-30T07:41:39.271Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2012
File: crates/js_api/src/registry.rs:485-512
Timestamp: 2025-07-30T07:41:39.271Z
Learning: In crates/js_api/src/registry.rs, findolor considers the current concurrent fetching of order files using futures::future::join_all without concurrency limits to be acceptable, preferring the simple approach over adding concurrency limiting mechanisms for the DotrainRegistry implementation.

Applied to files:

  • crates/cli/src/commands/local_db/sync/runner/mod.rs
🧬 Code graph analysis (3)
crates/common/src/local_db/sync.rs (1)
crates/common/src/local_db/address_collectors.rs (2)
  • collect_store_addresses (28-52)
  • collect_token_addresses (6-26)
crates/common/src/local_db/mod.rs (4)
crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
  • fetch (241-248)
crates/cli/src/commands/local_db/sync/data_source.rs (2)
  • fetch (51-52)
  • fetch (59-73)
crates/cli/src/commands/local_db/sync/token.rs (1)
  • fetch (106-108)
crates/cli/src/commands/local_db/sync/runner/apply.rs (1)
  • fetch (229-231)
crates/cli/src/commands/local_db/sync/runner/mod.rs (1)
crates/common/src/local_db/address_collectors.rs (1)
  • collect_store_addresses (28-52)
🔇 Additional comments (4)
crates/common/src/local_db/sync.rs (1)

2-2: Import path update looks good.

The switch to address_collectors keeps the existing behavior intact while aligning with the module rename.

crates/cli/src/commands/local_db/sync/runner/mod.rs (1)

19-19: Consistent refactor application.

Runner now targets the new address_collectors module, so everything stays aligned with the shared helpers.

crates/common/src/local_db/mod.rs (2)

1-1: Module rename exported cleanly.

Exposing address_collectors at the crate root keeps downstream imports straightforward after the file move.


75-81: Stronger token metadata error reporting.

The dedicated TokenMetadataFetchFailed variant with readable messaging gives callers actionable context without altering existing flows.

Also applies to: 153-160


Comment @coderabbitai help to get the list of available commands and usage tips.

@findolor
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 23, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4537af4 and c94d71e.

📒 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 use to_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 on LocalDbError and provides more detailed error context than the default Display implementation.

⛔ 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 complete

Verification confirms no stale re-exports or code referencing the removed local_db::tokens module. The new address_collectors export is correctly utilized across sync operations. The tokens module found in settings/remote is 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::tokens imports remain, new path is properly resolved, and all function usages are consistent across the codebase. The module reorganization is sound.

Comment on lines +41 to +47
Err(RetryError::Operation(err)) => {
Err(LocalDbError::TokenMetadataFetchFailed {
address: addr,
attempts: max_attempts,
source: Box::new(err),
})
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

“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)
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

Suggested change
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Base automatically changed from local-db-stmt-refactor to main October 31, 2025 09:23
@findolor findolor merged commit b2bc6dd into main Oct 31, 2025
19 checks passed
@findolor findolor deleted the local-db-token-metadata-err branch October 31, 2025 10:58
@github-actions
Copy link
Copy Markdown
Contributor

@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:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 31, 2025

Tip

For best results, initiate chat on the files or code changes.

SIZE=M


🧠 Learnings used
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:42.275Z
Learning: For PR #1884, after each commit review, I should provide a new comment with a PR size report in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding irrelevant files such as lock files (package-lock.json, cargo.lock, etc.).

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:42.275Z
Learning: After each commit in PR #1884, I should provide a new comment with the PR size report in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`. The report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the format: "TOTAL=number ADDITIONS=number DELETIONS=number". This report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". This report should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T22:46:08.530Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report should be the only content in the comment - no text before it, no text after it, no formatting blocks, just the raw report in the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1971
File: .github/workflows/vercel-docs-prod.yaml:32-34
Timestamp: 2025-07-11T12:30:09.245Z
Learning: findolor prefers not to pin Node versions explicitly in GitHub Actions workflows when using Nix with webapp-shell, considering the current setup sufficient for deterministic builds in the rainlanguage/rain.orderbook project.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1971
File: .github/workflows/vercel-docs-prod.yaml:10-14
Timestamp: 2025-07-11T12:29:49.284Z
Learning: In GitHub Actions workflows for the rainlanguage/rain.orderbook project, findolor is comfortable with job names that may seem misleading (like "Deploy-Docs-Preview" in a production workflow) when there's only one job in the workflow, as the context makes it clear enough.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.717Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2117
File: crates/js_api/src/gui/select_tokens.rs:421-424
Timestamp: 2025-09-02T08:04:34.729Z
Learning: User findolor in the rainlanguage/rain.orderbook codebase prefers not to change test code when tests are already passing, even if there appear to be type mismatches or potential issues. Working tests should be left alone unless there are actual errors.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/fuzz/mod.rs:64-64
Timestamp: 2025-07-04T09:02:57.301Z
Learning: In rainlanguage/rain.orderbook, user findolor prefers to limit type consistency changes to only the parts directly related to the current work scope. For example, when updating chain_id fields from u64 to u32 in fuzz-related code, unrelated files like tauri-app wallet commands can remain as u64 if they serve different purposes and aren't part of the current changes.

Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.

Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: tauri-app/src/routes/orders/[chainId]-[orderbook]-[orderHash]/+page.svelte:76-78
Timestamp: 2025-07-31T19:03:56.594Z
Learning: In the rainlanguage/rain.orderbook project, when the Tauri app has issues preventing proper testing, the team prefers to defer Tauri-specific implementations to separate PRs rather than including untested code, especially for financial operations like withdrawals.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2163
File: packages/webapp/src/routes/deploy/[orderName]/[deploymentKey]/fullDeployment.test.ts:214-215
Timestamp: 2025-09-24T11:06:36.718Z
Learning: In the rain.orderbook project, findolor is comfortable with public token addresses in test files even when they trigger Gitleaks warnings, as these are legitimate public addresses and not actual secrets requiring annotation or refactoring.

Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1994
File: crates/common/src/raindex_client/vaults.rs:59-59
Timestamp: 2025-07-16T05:52:05.576Z
Learning: User findolor prefers to handle documentation updates for getter methods in batch via dedicated PRs rather than addressing them individually during feature development, as mentioned for the formatted amount string fields in crates/common/src/raindex_client/vaults.rs.

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.

Rename tokens.rs to Reflect Address Collection Responsibilities Preserve Source Errors in Token Metadata Fetch Failures

3 participants