jackwener/OpenCLI · error · CliError

NO_DATA

NO_DATA

Error message

eastmoney returned no rank data

What it means

After a successful HTTP response, the eastmoney rank CLI expects data.data.diff to be a non-empty array of ranking rows. If the response JSON has no diff array or it is empty, it throws CliError NO_DATA with context 'market=<market> sort=<sortKey>'. This means eastmoney answered OK but returned no ranking data for the requested market/sort.

Source

Thrown at clis/eastmoney/rank.js:78

    const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');
    url.searchParams.set('pn', '1');
    url.searchParams.set('pz', String(limit));
    url.searchParams.set('po', sort.order === 'desc' ? '1' : '0');
    url.searchParams.set('np', '1');
    url.searchParams.set('fltt', '2');
    url.searchParams.set('invt', '2');
    url.searchParams.set('fid', sort.fid);
    url.searchParams.set('fs', fs);
    url.searchParams.set('fields', FIELDS);
    url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');

    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0', Accept: 'application/json' } });
    if (!resp.ok) throw new CliError('HTTP_ERROR', `eastmoney rank failed: HTTP ${resp.status}`);
    const data = await resp.json();
    const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];
    if (diff.length === 0) {
      throw new CliError('NO_DATA', 'eastmoney returned no rank data', `market=${market} sort=${sortKey}`);
    }

    return diff.slice(0, limit).map((it, i) => ({
      rank: i + 1,
      code: it.f12,
      name: it.f14,
      price: it.f2,
      changePercent: it.f3,
      change: it.f4,
      turnover: it.f6,
      volume: it.f5,
      turnoverRate: it.f8,
      peDynamic: it.f9,
      marketCap: it.f20,
    }));
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the market argument is a valid one supported by the CLI (e.g. hsa, hkn) and re-run
  2. Try a different sort key to confirm the API returns data for other queries
  3. Inspect the raw endpoint with curl using the same fs/fid params to see what eastmoney actually returns
  4. Update the CLI if eastmoney changed its response schema (diff no longer an array)

Example fix

// before
rank({ market: 'hsaa', sort: 'change' }); // invalid market -> empty diff
// after
rank({ market: 'hsa', sort: 'change' });
Defensive patterns

Strategy: try-catch

Validate before calling

const VALID_MARKETS = ['hsa','hkn'];
if (!VALID_MARKETS.includes(args.market)) throw new Error(`unsupported market: ${args.market}`);

Type guard

function hasRankData(data) { return Array.isArray(data?.data?.diff) && data.data.diff.length > 0; }

Try / catch

try {
  const rows = await rank({ market, sort });
} catch (e) {
  if (e.code === 'NO_DATA') {
    console.warn(`no rank data for ${e.detail ?? market}; try another market/sort`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling rank with a market/fs combination that has no rows (e.g. an invalid or empty market filter), eastmoney returning {data:null} for a deprecated field set, or an off-hours/regulatory window where the queried list is empty.

Common situations: Typo'd or unsupported market argument, eastmoney silently returning empty payloads for certain fs values, API schema changes where diff moves or becomes an object instead of an array.

Related errors


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