jackwener/OpenCLI · error · CommandExecutionError

coingecko returned error: ${data.error}

Error message

coingecko returned error: ${data.error}

What it means

This CommandExecutionError is thrown when the JSON body parses but contains an { error: ... } field, i.e. CoinGecko returned a structured API error inside a 2xx-style response. The library surfaces the API's own error message verbatim. This is a server-side rejection that must be read from the payload, not from the status code.

Source

Thrown at clis/coingecko/top.js:48

    url.searchParams.set('order', 'market_cap_desc');
    url.searchParams.set('per_page', String(limit));
    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. Read the embedded error text in the thrown message — it states the exact API complaint.
  2. Fix the offending parameter (most commonly vs_currency) per the message.
  3. Validate your currency/args against /simple/supported_vs_currencies before calling.
  4. Slow down if the error mentions rate limits or upgrade to a Pro key.
  5. Check CoinGecko changelog if the error indicates a deprecated endpoint/parameter.

Example fix

// before
await runCli('coingecko', 'top', ['--currency', 'us dollars']);
// after
const cur = String(rawCur).trim().toLowerCase();
if (!/^[a-z]{2,6}$/.test(cur)) throw new Error('bad currency: ' + rawCur);
await runCli('coingecko', 'top', ['--currency', cur]);
Defensive patterns

Strategy: try-catch

Validate before calling

const list = await (await fetch('https://api.coingecko.com/api/v3/simple/supported_vs_currencies')).json();
if (!list.includes(cur)) throw new Error('unsupported vs_currency: ' + cur);

Type guard

function isApiErrorPayload(d) { return d !== null && typeof d === 'object' && typeof d.error === 'string'; }

Try / catch

try {
  rows = await runCli('coingecko', 'top', opts);
} catch (e) {
  if (/coingecko returned error:/.test(e.message)) {
    console.error('CoinGecko API said:', e.message.replace('coingecko returned error: ', ''));
  }
  throw e;
}

Prevention

When it happens

Trigger: CoinGecko responding with JSON like {"error":"Invalid vs_currency"} or rate-limit/plan messages embedded in the body; deprecated parameter errors returned as JSON.

Common situations: Unsupported vs_currency values; demo-key endpoints hit with pro-only parameters; API version drift returning descriptive error objects; bursts hitting soft limits returned as JSON errors.

Related errors


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