omi icon indicating copy to clipboard operation
omi copied to clipboard

fix(coingecko): prevent dict iteration crash on error payloads, add lifespan client fallback, and add hermetic unit tests

Open Ivansky1 opened this issue 2 months ago • 1 comments

Description

In plugins/omi-coingecko-crypto-app, several runtime bugs and unhandled exceptions can crash the service or fail requests:

  1. Fatal Dict Iteration Crash in get_crypto_market_overview: The /coins/markets endpoint on CoinGecko returns a list on success, but returns a JSON dictionary on errors (such as HTTP 429 rate limiting or invalid parameters, e.g. {"status": {"error_code": 429, "error_message": "..."}} or {"error": "..."}). Because if not markets: evaluates to False for non-empty dictionaries, the handler proceeds to for coin in markets:. In Python, iterating over a dictionary yields its string keys ("status"), causing coin.get("market_cap_rank") to crash with fatal AttributeError: 'str' object has no attribute 'get'.

  2. Unhandled Non-Dict Payloads in get_crypto_price, search_crypto_coins, get_trending_crypto: If CoinGecko returns unexpected non-dict payloads or error structures, calling .get(...) causes unhandled exceptions rather than clean user-facing error messages.

  3. Missing Lifespan Client Fallback in _fetch_coingecko: app.state.http_client is accessed directly. If the app is initialized outside lifespan or during testing, app.state raises AttributeError: 'State' object has no attribute 'http_client'. A graceful fallback to a scoped httpx.AsyncClient is needed.

  4. Numeric Format Strings Crash: In get_trending_crypto, price_btc can be returned as a string or float from upstream. Direct formatting with {price_btc:.8f} raises ValueError: Unknown format code 'f' for object of type 'str'. Furthermore, format helpers _format_currency, _format_compact, and _format_percentage should defensively cast inputs to float with safe fallback.

  5. Pydantic v2 Whitespace Normalization: Validators for vs_currency and query require mode="before" to strip whitespace before string length checks.

  6. Missing Hermetic Unit Tests & Manifest Registration: The plugin currently only contains smoke_test.py that depends on live network access. A 100% hermetic stdlib unit test suite is needed and should be registered in .github/checks-manifest.yaml.


Bounty Payout Destination (Base USDC / EVM): 0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0

Ivansky1 avatar Sep 14 '26 21:09 Ivansky1

Already on current main (a979f6239c).

plugins/omi-coingecko-crypto-app/main.py already uses _as_dict / _as_list before iterating payloads. Closing as completed.

aryanorastar avatar Sep 22 '26 05:09 aryanorastar