{"record":{"id":"23d710438494ed26","repo":"jackwener/OpenCLI","slug":"coingecko-currency-must-look-like-a-currency-slug","errorCode":null,"errorMessage":"coingecko currency must look like a currency slug (got \"${args.currency}\")","messagePattern":"coingecko currency must look like a currency slug \\(got \"(.+?)\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/coingecko/coin.js","lineNumber":36,"sourceCode":"        { name: 'id', positional: true, required: true, type: 'string', help: 'CoinGecko coin id (lowercase, e.g. bitcoin / ethereum / solana).' },\n        { name: 'currency', type: 'string', default: 'usd', help: 'Quote currency (usd, cny, eur, jpy, ...).' },\n    ],\n    columns: [\n        'id', 'symbol', 'name', 'rank', 'price', 'marketCap', 'volume24h',\n        'change24hPct', 'change7dPct', 'change30dPct', 'ath', 'athDate', 'atl', 'atlDate',\n        'circulatingSupply', 'totalSupply', 'maxSupply', 'genesisDate', 'homepage',\n    ],\n    func: async (args) => {\n        const id = String(args.id ?? '').trim().toLowerCase();\n        if (!id) {\n            throw new ArgumentError('coingecko coin id cannot be empty', 'Example: opencli coingecko coin bitcoin');\n        }\n        if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) {\n            throw new ArgumentError(`coingecko coin id must look like a CoinGecko slug (got \"${args.id}\")`);\n        }\n        const currency = String(args.currency ?? 'usd').trim().toLowerCase();\n        if (!/^[a-z0-9-]{2,20}$/.test(currency)) {\n            throw new ArgumentError(`coingecko currency must look like a currency slug (got \"${args.currency}\")`);\n        }\n\n        const url = new URL(`https://api.coingecko.com/api/v3/coins/${id}`);\n        url.searchParams.set('localization', 'false');\n        url.searchParams.set('tickers', 'false');\n        url.searchParams.set('market_data', 'true');\n        url.searchParams.set('community_data', 'false');\n        url.searchParams.set('developer_data', 'false');\n        url.searchParams.set('sparkline', 'false');\n\n        let resp;\n        try {\n            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n        } catch (error) {\n            throw new CommandExecutionError(`coingecko coin request failed: ${error?.message || error}`);\n        }\n        if (resp.status === 404) {\n            throw new EmptyResultError('coingecko coin', `coingecko has no coin with id \"${id}\".`);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coingecko/coin.js#L18-L54","documentation":"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.","triggerScenarios":"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').","commonSituations":"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.","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'"],"exampleFix":"// before\nopencli coingecko coin bitcoin --currency $USD\n// after\nopencli coingecko coin bitcoin --currency usd","handlingStrategy":"validation","validationCode":"const ccy = (raw ?? 'usd').trim().toLowerCase();\nif (!/^[a-z0-9-]{2,20}$/.test(ccy)) throw new Error(`Invalid currency slug: ${raw}`);","typeGuard":"const isCurrencySlug = (v) => typeof v === 'string' && /^[a-z0-9-]{2,20}$/.test(v.trim().toLowerCase());","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["cli","argument-validation","regex-validation"],"backgroundTag":"invalid-slug-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}