jackwener/OpenCLI · error · CommandExecutionError

coingecko trending request failed: ${error?.message || error

Error message

coingecko trending request failed: ${error?.message || error}

What it means

This CommandExecutionError wraps any low-level fetch() rejection while calling the CoinGecko trending endpoint (https://api.coingecko.com/api/v3/search/trending). The fetch itself threw — meaning no HTTP response was received at all — so the library surfaces the underlying error message (DNS failure, connection reset, TLS error, abort, etc.) prefixed with context. It indicates a network-layer problem, not an API-level HTTP error status.

Source

Thrown at clis/coingecko/trending.js:24

} from '@jackwener/opencli/errors';

cli({
    site: 'coingecko',
    name: 'trending',
    access: 'read',
    description: 'Top trending cryptocurrencies on CoinGecko in the last 24h (search-volume based).',
    domain: 'api.coingecko.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [],
    columns: ['rank', 'id', 'symbol', 'name', 'marketCapRank', 'priceBtc', 'thumb'],
    func: async () => {
        const url = 'https://api.coingecko.com/api/v3/search/trending';
        let resp;
        try {
            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
        } catch (error) {
            throw new CommandExecutionError(`coingecko trending request failed: ${error?.message || error}`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError('coingecko returned HTTP 429 (rate limited)', 'Wait and retry.');
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`coingecko trending failed: HTTP ${resp.status}`);
        }
        let data;
        try {
            data = await resp.json();
        } catch (error) {
            throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);
        }
        const coins = Array.isArray(data?.coins) ? data.coins : [];
        if (coins.length === 0) {
            throw new EmptyResultError('coingecko trending', 'coingecko returned no trending coins.');
        }
        return coins.map((entry, i) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check basic connectivity: curl -I https://api.coingecko.com/api/v3/search/trending
  2. If behind a proxy, configure HTTPS_PROXY / NODE_EXTRA_CA_CERTS so Node's fetch can reach the host
  3. Upgrade to Node >= 18 where global fetch exists (TypeError 'fetch is not a function' means missing fetch)
  4. Retry after checking status.coingecko.com in case of an outage

Example fix

// before (Node 16)
$ coingecko trending  // TypeError: fetch is not a function -> wrapped in this error
// after
$ nvm use 18 && coingecko trending
Defensive patterns

Strategy: retry

Validate before calling

const hasFetch = typeof globalThis.fetch === 'function';
if (!hasFetch) throw new Error('Node >= 18 required for global fetch');
await fetch('https://api.coingecko.com/api/v3/ping', { method: 'HEAD' }); // connectivity precheck

Type guard

function isFetchNetworkError(e) {
  return e instanceof TypeError || /fetch failed|ENOTFOUND|ECONNREFUSED|ECONNRESET|ETIMEDOUT/.test(String(e?.cause?.code || e?.message));
}

Try / catch

try {
  await runCli('coingecko trending');
} catch (e) {
  if (/trending request failed/.test(e.message)) {
    // network layer: check connectivity/proxy, then retry with backoff
    await new Promise(r => setTimeout(r, 5000));
    await runCli('coingecko trending');
  } else throw e;
}

Prevention

When it happens

Trigger: The `await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } })` call in the trending command rejects: no internet connectivity, DNS resolution failure for api.coingecko.com, connection refused/timeout, TLS interception, or a Node version without global fetch (<18). The catch block immediately rethrows as CommandExecutionError with `${error?.message || error}`.

Common situations: Running the CLI offline or behind a corporate proxy/firewall that blocks api.coingecko.com, DNS misconfiguration, VPN dropping mid-command, or running on Node < 18 where fetch is undefined (TypeError: fetch is not a function).

Related errors


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