{"record":{"id":"d905b58b02d2db46","repo":"jackwener/OpenCLI","slug":"coingecko-top","errorCode":null,"errorMessage":"coingecko top","messagePattern":"coingecko top","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/coingecko/top.js","lineNumber":50,"sourceCode":"    url.searchParams.set('page', '1');\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 top request failed: ${error?.message || error}`);\n    }\n    if (!resp.ok) throw new CommandExecutionError(`coingecko top failed: HTTP ${resp.status}`);\n    let data;\n    try {\n      data = await resp.json();\n    } catch (error) {\n      throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);\n    }\n    if (data?.error) throw new CommandExecutionError(`coingecko returned error: ${data.error}`);\n    if (!Array.isArray(data)) throw new CommandExecutionError('coingecko returned an unexpected response');\n    if (data.length === 0) throw new EmptyResultError('coingecko top', 'coingecko returned no market data');\n\n    return data.map((c) => ({\n      rank: c.market_cap_rank,\n      symbol: String(c.symbol ?? '').toUpperCase(),\n      name: c.name,\n      price: c.current_price,\n      change24hPct: c.price_change_percentage_24h,\n      marketCap: c.market_cap,\n      volume24h: c.total_volume,\n      high24h: c.high_24h,\n      low24h: c.low_24h,\n    }));\n  },\n});\n","sourceCodeStart":32,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coingecko/top.js#L32-L65","documentation":"This EmptyResultError is thrown by the coingecko top command when the CoinGecko /markets API responds successfully with valid JSON, but the response array is empty. The library treats a successful HTTP response containing zero market entries as a command-level 'no data' condition rather than a failure of the request itself. It signals that the query executed fine but CoinGecko had no rows to return for the requested coins/currency.","triggerScenarios":"Calling `coingecko top` when the resolved market query matches no listings — e.g. requesting ids that don't exist on CoinGecko, an unsupported vs_currency, or CoinGecko legitimately returning [] (e.g. brand-new/unknown coin ids or delisted assets). The response must pass the Array.isArray check with length 0 to reach this throw.","commonSituations":"Typo'd or stale coin ids (renamed/delisted projects), a vs_currency code CoinGecko doesn't support, scripts hard-coding coin symbols instead of CoinGecko ids, or API behavior changes where the endpoint returns [] instead of an error.","solutions":["Check the coin ids passed to the command; CoinGecko expects ids like 'bitcoin', not symbols like 'BTC'","Verify the --currency (vs_currency) code is supported by CoinGecko (e.g. 'usd', 'eur')","Re-run without filters/limit to confirm the API returns data at all","Check https://status.coingecko.com or retry later if the API is degraded and returning empty payloads"],"exampleFix":"// before\nawait runCli('coingecko top', '--ids', 'BTC'); // symbol, not id -> empty result\n// after\nawait runCli('coingecko top', '--ids', 'bitcoin'); // use CoinGecko id","handlingStrategy":"validation","validationCode":"const ids = ['bitcoin', 'ethereum'];\nconst currency = 'usd';\nif (!ids.every(id => /^[a-z0-9-]+$/.test(id))) throw new Error('ids must be CoinGecko ids (lowercase), not symbols');","typeGuard":"function hasMarkets(d) {\n  return Array.isArray(d) && d.length > 0 && typeof d[0]?.id === 'string';\n}","tryCatchPattern":"try {\n  const rows = await runCli('coingecko top', '--ids', ids.join(','));\n  if (!rows.length) throw new EmptyResultError('coingecko top');\n} catch (e) {\n  if (/returned no market data/.test(e.message)) console.warn('no data for ids:', ids);\n  else throw e;\n}","preventionTips":["Always use CoinGecko coin ids (bitcoin, ethereum) not symbols (BTC, ETH)","Keep a local id map and validate ids before invoking the command","Treat empty results as data-dependent, retry with broader query or different currency"],"tags":["empty-result","api-response","coingecko","cli"],"backgroundTag":"empty-api-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}