{"record":{"id":"c6fdea15e8c5a52a","repo":"jackwener/OpenCLI","slug":"coingecko-returned-no-trending-coins","errorCode":null,"errorMessage":"coingecko returned no trending coins.","messagePattern":"coingecko returned no trending coins\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/coingecko/trending.js","lineNumber":40,"sourceCode":"            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n        } catch (error) {\n            throw new CommandExecutionError(`coingecko trending request failed: ${error?.message || error}`);\n        }\n        if (resp.status === 429) {\n            throw new CommandExecutionError('coingecko returned HTTP 429 (rate limited)', 'Wait and retry.');\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`coingecko trending failed: HTTP ${resp.status}`);\n        }\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        const coins = Array.isArray(data?.coins) ? data.coins : [];\n        if (coins.length === 0) {\n            throw new EmptyResultError('coingecko trending', 'coingecko returned no trending coins.');\n        }\n        return coins.map((entry, i) => {\n            const c = entry?.item || {};\n            return {\n                rank: i + 1,\n                id: c.id || '',\n                symbol: String(c.symbol || '').toUpperCase(),\n                name: c.name || '',\n                marketCapRank: c.market_cap_rank ?? null,\n                priceBtc: c.price_btc ?? null,\n                thumb: c.thumb || c.small || c.large || '',\n            };\n        });\n    },\n});\n","sourceCodeStart":22,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coingecko/trending.js#L22-L56","documentation":"This EmptyResultError is thrown when the CoinGecko trending response parses successfully but data.coins is missing, not an array, or an empty array. The library defensively defaults a non-array coins field to [] and then signals 'no trending coins' as a command-level empty result. It means CoinGecko answered 200 with a shape that contains no trending entries.","triggerScenarios":"Calling `coingecko trending` when CoinGecko returns 200 with data.coins === [] or an unexpected payload shape (e.g. an error object without a coins field, or an API schema change where trending coins moved to a different key). `Array.isArray(data?.coins) ? data.coins : []` yields length 0, triggering the throw.","commonSituations":"CoinGecko quietly changing the trending response schema (coins renamed/nested differently), a degraded/empty response during API incidents, or a proxy/cached response returning an empty JSON object {}.","solutions":["Re-run the command to rule out a transient empty response","Log/inspect the raw response body to confirm the current schema still has data.coins as a non-empty array","If the schema changed, pin/report the library version and check for updates that track the new CoinGecko response shape","Fallback to a different CoinGecko endpoint (e.g. /search or /coins/markets sorted by volume) if trending stays empty"],"exampleFix":"null","handlingStrategy":"fallback","validationCode":"null","typeGuard":"function hasTrendingCoins(d) {\n  return d && Array.isArray(d.coins) && d.coins.length > 0 && d.coins[0]?.item?.id;\n}","tryCatchPattern":"try {\n  const trending = await runCli('coingecko trending');\n} catch (e) {\n  if (/returned no trending coins/.test(e.message)) {\n    return runCli('coingecko top'); // fallback to markets data\n  }\n  throw e;\n}","preventionTips":["Log the raw response body when empty to detect CoinGecko schema changes","Pin library versions and update when CoinGecko changes the trending schema","Have a fallback data source (markets endpoint sorted by volume)","Treat empty trending as transient; retry once before falling back"],"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"}