jackwener/OpenCLI · error · ArgumentError

coingecko coin id must look like a CoinGecko slug (got "${ar

Error message

coingecko coin id must look like a CoinGecko slug (got "${args.id}")

What it means

This ArgumentError is thrown when the coin id does not match the slug pattern /^[a-z0-9][a-z0-9-]*$/. CoinGecko coin ids are lowercase slugs like 'bitcoin' or 'avalanche-2'; anything containing uppercase letters, spaces, underscores, symbols, or starting with a hyphen is rejected before an API call is made. The raw args.id is echoed in the message to show what failed validation.

Source

Thrown at clis/coingecko/coin.js:32

    domain: 'api.coingecko.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'id', positional: true, required: true, type: 'string', help: 'CoinGecko coin id (lowercase, e.g. bitcoin / ethereum / solana).' },
        { name: 'currency', type: 'string', default: 'usd', help: 'Quote currency (usd, cny, eur, jpy, ...).' },
    ],
    columns: [
        'id', 'symbol', 'name', 'rank', 'price', 'marketCap', 'volume24h',
        'change24hPct', 'change7dPct', 'change30dPct', 'ath', 'athDate', 'atl', 'atlDate',
        'circulatingSupply', 'totalSupply', 'maxSupply', 'genesisDate', 'homepage',
    ],
    func: async (args) => {
        const id = String(args.id ?? '').trim().toLowerCase();
        if (!id) {
            throw new ArgumentError('coingecko coin id cannot be empty', 'Example: opencli coingecko coin bitcoin');
        }
        if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) {
            throw new ArgumentError(`coingecko coin id must look like a CoinGecko slug (got "${args.id}")`);
        }
        const currency = String(args.currency ?? 'usd').trim().toLowerCase();
        if (!/^[a-z0-9-]{2,20}$/.test(currency)) {
            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) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the lowercase CoinGecko slug, e.g. `opencli coingecko coin bitcoin` not `BTC`
  2. Lowercase the input and replace spaces/underscores with hyphens before invoking
  3. Verify the exact id on coingecko.com (the coin's URL path segment is the id)

Example fix

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

Strategy: validation

Validate before calling

const slug = raw.trim().toLowerCase();
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) throw new Error(`Not a CoinGecko slug: ${raw}`);

Type guard

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

Try / catch

try { await run(['coingecko', 'coin', id]); } catch (e) { if (/must look like a CoinGecko slug/.test(e.message)) { console.error('Use a lowercase slug like bitcoin, not a symbol/name.'); } }

Prevention

When it happens

Trigger: Passing an id with uppercase letters ('Bitcoin'), spaces ('lite coin'), underscores ('binance_coin'), a ticker instead of a slug ('BTC'), a URL ('https://coingecko.com/en/coins/bitcoin'), or a leading hyphen.

Common situations: Using the coin's display name or symbol instead of its CoinGecko id; pasting a coingecko.com URL; shell uppercasing or interpolating a symbol variable.

Related errors


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