jackwener/OpenCLI · error · ArgumentError
coingecko currency must look like a currency slug (got "${ar
Error message
coingecko currency must look like a currency slug (got "${args.currency}") What it means
This ArgumentError is thrown when the `currency` argument fails the pattern /^[a-z0-9-]{2,20}$/. The currency is used both as a query parameter and as the key into market_data maps (current_price[currency]), so it must be a clean 2-20 char slug. The raw args.currency is echoed in the message.
Source
Thrown at clis/coingecko/coin.js:36
{ 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) {
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}".`);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain lowercase currency slug such as usd, eur, cny, jpy, gbp
- Remove symbols/underscores/spaces from the currency argument (use 2-4 letter codes like 'usd')
- Omit the --currency flag entirely to use the default 'usd'
Example fix
// before opencli coingecko coin bitcoin --currency $USD // after opencli coingecko coin bitcoin --currency usd
Defensive patterns
Strategy: validation
Validate before calling
const ccy = (raw ?? 'usd').trim().toLowerCase();
if (!/^[a-z0-9-]{2,20}$/.test(ccy)) throw new Error(`Invalid currency slug: ${raw}`); Type guard
const isCurrencySlug = (v) => typeof v === 'string' && /^[a-z0-9-]{2,20}$/.test(v.trim().toLowerCase()); Try / catch
try { await run(['coingecko', 'coin', id, '--currency', ccy]); } catch (e) { if (/currency must look like/.test(e.message)) { console.error('Use a plain code like usd, eur, jpy.'); process.exit(2); } throw e; } Prevention
- Use ISO-style lowercase currency codes (usd, eur, jpy), never symbols ($, €) or names
- Whitelist allowed currencies in your wrapper scripts
- Omit --currency to get the usd default
When it happens
Trigger: Passing a currency that is empty, 1 character, longer than 20 chars, or contains invalid characters like '$', '_', spaces, or uppercase after normalization (e.g. '$USD', 'us_dollar', 'US Dollar').
Common situations: Passing a currency symbol ('$','€','¥') instead of a slug; passing a full currency name with spaces; passing an ISO code with trailing whitespace or a region suffix that breaks the pattern.
Related errors
- coingecko coin id must look like a CoinGecko slug (got "${ar
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/23d710438494ed26.
Report an issue: GitHub.