jackwener/OpenCLI · error · EmptyResultError

coingecko has no coin with id "${id}".

Error message

coingecko has no coin with id "${id}".

What it means

This EmptyResultError is thrown when the CoinGecko API responds with HTTP 404, meaning no coin exists for the given id. The command treats this as 'empty result' rather than a hard failure, since a wrong-but-well-formed slug simply doesn't match any listed coin. The message names the entity and echoes the id queried.

Source

Thrown at clis/coingecko/coin.js:54

            throw new ArgumentError(`coingecko currency must look like a currency slug (got "${args.currency}")`);
        }

        const url = new URL(`https://api.coingecko.com/api/v3/coins/${id}`);
        url.searchParams.set('localization', 'false');
        url.searchParams.set('tickers', 'false');
        url.searchParams.set('market_data', 'true');
        url.searchParams.set('community_data', 'false');
        url.searchParams.set('developer_data', 'false');
        url.searchParams.set('sparkline', 'false');

        let resp;
        try {
            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
        } catch (error) {
            throw new CommandExecutionError(`coingecko coin request failed: ${error?.message || error}`);
        }
        if (resp.status === 404) {
            throw new EmptyResultError('coingecko coin', `coingecko has no coin with id "${id}".`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError('coingecko returned HTTP 429 (rate limited)', 'Free tier allows ~30 calls/min. Wait and retry.');
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`coingecko coin 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}`);
        }

        const md = data.market_data || {};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the exact id on coingecko.com (the coin's URL path is its id, e.g. /en/coins/avalanche-2)
  2. Use CoinGecko's /search endpoint (`https://api.coingecko.com/api/v3/search?query=<name>`) to find the correct id
  3. Handle EmptyResultError in your script and fall back to a search or a corrected id list

Example fix

// before
opencli coingecko coin bitcon
// after
opencli coingecko coin bitcoin
Defensive patterns

Strategy: try-catch

Validate before calling

const KNOWN = new Set(['bitcoin','ethereum','solana','avalanche-2']);
if (!KNOWN.has(id)) console.warn(`Unverified coin id: ${id} — may 404`);

Type guard

const isKnownCoinId = (v) => typeof v === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(v) && knownIdsFromSearchApi.has(v);

Try / catch

try { const rows = await run(['coingecko', 'coin', id]); } catch (e) { if (e instanceof EmptyResultError || /has no coin with id/.test(e.message)) { return lookupIdViaSearch(name); } throw e; }

Prevention

When it happens

Trigger: Calling `opencli coingecko coin <id>` where <id> passes slug validation but doesn't exist on CoinGecko — misspelled slugs ('bitcon'), delisted coins, ids for coins only on other aggregators, or test/garbage slugs.

Common situations: Typo in the coin id; using a coin's name with wrong spelling; querying a newly listed or delisted token whose id differs from expected; hardcoding ids from a different data source (CMC ids differ from CoinGecko ids).

Related errors


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