Repository navigation
fix(transfer): never report a failed balance lookup as a successful Result - #12
Merged
Merged
Conversation
…esult An RPC failure in _get_native_balance / _get_erc20_balance / _get_l1_native_balance used to write "Error: ..." (or "Not connected") into the entry's `balance` field, and get_chain_wallet_balance wrapped that entry in Result.ok. Consumers doing Decimal(balance) then raised decimal.ConversionSyntax, and the poisoned Result sat in the 10 s balance cache. Seen in TradeBots on 2026-09-19 after an Avalanche RPC HTTP 500 on eth_getBalance. - Failed entries now carry balance=None plus an `error` key (_balance_error_entry); no string sentinel ever lands in `balance`. - get_chain_wallet_balance returns Result.fail for any error entry (L1, native and ERC20 paths alike). - get_chain_wallet_balances / get_all_chain_wallet_balances drop failed entries from chain_balances, report them in an additive `errors` list, and fail only when every lookup failed. _fetch_erc20_balances_list emits error entries instead of silently skipping failed tokens. - ttl_cached / async_ttl_cached no longer store a Result with success=False, in any tier; stampede waiters still receive it. - _sanitize_error gains a `level` kwarg (default ERROR, unchanged); balance helpers log at WARNING without a traceback. Docs: README, user guide, error-handling, sdk-caching, remediation plan (new H-6), CLAUDE.md non-obvious decisions.
ngurmen
requested review from
ilkerulutas
and removed request for
ilkerulutas
September 20, 2026 09:12
ilkerulutas
approved these changes
Sep 20, 2026
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
Result.failfromget_chain_wallet_balancewhen the RPC read fails; previously an RPC 500 producedResult.ok({"balance": "Error: ..."}), which TradeBots turned intodecimal.ConversionSyntaxon 2026-09-19. Failed entries now carrybalance=Noneplus anerrorkey, never a string sentinel inbalance.get_chain_wallet_balances/get_all_chain_wallet_balancesthrough an additiveerrorslist instead of pushing error-string entries intochain_balances; the Result fails only when every lookup failed._fetch_erc20_balances_listreports failed tokens instead of silently dropping them.ttl_cached/async_ttl_cachedacross all four tiers; stampede waiters still receive the failure, the next caller retries. Rewrotetest_get_deployment_uses_cache, which was only "instant" because it cached a failure.levelkwarg to_sanitize_error(default ERROR, unchanged elsewhere); balance helpers log at WARNING without a traceback.docs/index.md(was stale at 0.4.0). Docs: README, user guide, error-handling, sdk-caching, remediation plan (new H-6), CLAUDE.md.Quality Gates
ruff check ./ruff format --check .cleanmypy --config-file mypy.ini --follow-imports=silentclean (61 files)pytest --cov=src --cov-fail-under=100 tests/unit(1201 passed, 100% coverage)bandit -r src --severity-level high+pip-audit --skip-editablecleanscripts/version_manager.py validatein sync at 0.6.2Behavioural changes
get_chain_wallet_balancenow fails instead of succeeding with a non-numericbalanceon RPC errors, unknown tokens, or Dexalot L1 not connected.errors: list[str]field; failed entries are no longer present inchain_balances.get_chain_token_balancesnow fails when a requested token's RPC read fails (it already failed for unknown tokens).Result.failis no longer served from cache for the TTL; the next call retries.