jackwener/OpenCLI · error · ArgumentError

coingecko coin id cannot be empty

Error message

coingecko coin id cannot be empty

What it means

This ArgumentError is thrown by the `coingecko coin` command when the required positional `id` argument is missing or empty after normalization (trim/lowercase of String(args.id ?? '')). The command needs a CoinGecko coin slug (e.g. 'bitcoin') to build the API URL https://api.coingecko.com/api/v3/coins/{id}, so an empty id would produce an invalid request. The error message includes an example usage to guide the caller.

Source

Thrown at clis/coingecko/coin.js:29

    name: 'coin',
    access: 'read',
    description: 'Fetch a single cryptocurrency\'s market data by CoinGecko id (e.g. bitcoin, ethereum).',
    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;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a valid CoinGecko coin id as the first positional argument, e.g. `opencli coingecko coin bitcoin`
  2. Check that the variable or pipeline feeding the id is non-empty before invoking the command
  3. Look up the correct coin id via CoinGecko's search API or website if unsure of the slug

Example fix

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

Strategy: validation

Validate before calling

const id = (process.argv[3] ?? '').trim().toLowerCase();
if (!id) { console.error('Usage: opencli coingecko coin <id>'); process.exit(2); }

Type guard

const isNonEmpty = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try { await run(['coingecko', 'coin', id]); } catch (e) { if (e instanceof ArgumentError) { console.error('Missing/invalid arg:', e.message); process.exit(2); } throw e; }

Prevention

When it happens

Trigger: Calling `opencli coingecko coin` with no positional id, passing an empty string (''), whitespace-only string (' '), or an arg that normalizes to empty (e.g. null/undefined coerced via args.id ?? '').

Common situations: Scripting the CLI where a variable holding the coin id is unset or empty; piping data where the id column was blank; copying a command template and forgetting to fill in the coin name.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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