jackwener/OpenCLI · warning · EmptyResultError

coingecko top

Error message

coingecko top

What it means

This EmptyResultError is thrown by the coingecko top command when the CoinGecko /markets API responds successfully with valid JSON, but the response array is empty. The library treats a successful HTTP response containing zero market entries as a command-level 'no data' condition rather than a failure of the request itself. It signals that the query executed fine but CoinGecko had no rows to return for the requested coins/currency.

Source

Thrown at clis/coingecko/top.js:50

    url.searchParams.set('page', '1');
    url.searchParams.set('sparkline', 'false');

    let resp;
    try {
      resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
    } catch (error) {
      throw new CommandExecutionError(`coingecko top request failed: ${error?.message || error}`);
    }
    if (!resp.ok) throw new CommandExecutionError(`coingecko top failed: HTTP ${resp.status}`);
    let data;
    try {
      data = await resp.json();
    } catch (error) {
      throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);
    }
    if (data?.error) throw new CommandExecutionError(`coingecko returned error: ${data.error}`);
    if (!Array.isArray(data)) throw new CommandExecutionError('coingecko returned an unexpected response');
    if (data.length === 0) throw new EmptyResultError('coingecko top', 'coingecko returned no market data');

    return data.map((c) => ({
      rank: c.market_cap_rank,
      symbol: String(c.symbol ?? '').toUpperCase(),
      name: c.name,
      price: c.current_price,
      change24hPct: c.price_change_percentage_24h,
      marketCap: c.market_cap,
      volume24h: c.total_volume,
      high24h: c.high_24h,
      low24h: c.low_24h,
    }));
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the coin ids passed to the command; CoinGecko expects ids like 'bitcoin', not symbols like 'BTC'
  2. Verify the --currency (vs_currency) code is supported by CoinGecko (e.g. 'usd', 'eur')
  3. Re-run without filters/limit to confirm the API returns data at all
  4. Check https://status.coingecko.com or retry later if the API is degraded and returning empty payloads

Example fix

// before
await runCli('coingecko top', '--ids', 'BTC'); // symbol, not id -> empty result
// after
await runCli('coingecko top', '--ids', 'bitcoin'); // use CoinGecko id
Defensive patterns

Strategy: validation

Validate before calling

const ids = ['bitcoin', 'ethereum'];
const currency = 'usd';
if (!ids.every(id => /^[a-z0-9-]+$/.test(id))) throw new Error('ids must be CoinGecko ids (lowercase), not symbols');

Type guard

function hasMarkets(d) {
  return Array.isArray(d) && d.length > 0 && typeof d[0]?.id === 'string';
}

Try / catch

try {
  const rows = await runCli('coingecko top', '--ids', ids.join(','));
  if (!rows.length) throw new EmptyResultError('coingecko top');
} catch (e) {
  if (/returned no market data/.test(e.message)) console.warn('no data for ids:', ids);
  else throw e;
}

Prevention

When it happens

Trigger: Calling `coingecko top` when the resolved market query matches no listings — e.g. requesting ids that don't exist on CoinGecko, an unsupported vs_currency, or CoinGecko legitimately returning [] (e.g. brand-new/unknown coin ids or delisted assets). The response must pass the Array.isArray check with length 0 to reach this throw.

Common situations: Typo'd or stale coin ids (renamed/delisted projects), a vs_currency code CoinGecko doesn't support, scripts hard-coding coin symbols instead of CoinGecko ids, or API behavior changes where the endpoint returns [] instead of an error.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/d905b58b02d2db46. Report an issue: GitHub.