jackwener/OpenCLI · warning · CliError

INVALID_ARGUMENT

INVALID_ARGUMENT

Error message

`Unknown market "${market}". Valid: ${Object.keys(MARKETS).join(', ')}`

What it means

The rank command validates --market against the MARKETS whitelist (hs-a, sh-a, sz-a, bj-a, cyb, kcb, hk, us). If the lowercased value has no entry, it throws CliError INVALID_ARGUMENT listing all valid keys. This guard prevents constructing a bogus fs (filter) parameter for the clist/get endpoint.

Source

Thrown at clis/eastmoney/rank.js:54

    access: 'read',
  description: '东财市场涨跌/成交排行(沪深/北证/创/科/港/美)',
  domain: 'push2.eastmoney.com',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'market', type: 'string', default: 'hs-a', help: '市场:hs-a / sh-a / sz-a / bj-a / cyb / kcb / hk / us' },
    { name: 'sort',   type: 'string', default: 'change', help: '排序:change / drop / turnover / volume / amplitude / rate' },
    { name: 'limit',  type: 'int',    default: 20,       help: '返回数量 (max 100)' },
  ],
  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'change', 'turnover', 'volume', 'turnoverRate', 'peDynamic', 'marketCap'],
  func: async (args) => {
    const market = String(args.market ?? 'hs-a').toLowerCase();
    const sortKey = String(args.sort ?? 'change').toLowerCase();
    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));

    const fs = MARKETS[market];
    if (!fs) {
      throw new CliError('INVALID_ARGUMENT', `Unknown market "${market}". Valid: ${Object.keys(MARKETS).join(', ')}`);
    }
    const sort = SORTS[sortKey];
    if (!sort) {
      throw new CliError('INVALID_ARGUMENT', `Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(', ')}`);
    }

    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');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the exact valid values: hs-a, sh-a, sz-a, bj-a, cyb, kcb, hk, us
  2. Run `eastmoney rank --help` to see accepted market names
  3. Lowercase and hyphenate: 'hs-a' not 'hsa' or 'HS A'
  4. In scripts, validate the market variable against the same list before invoking

Example fix

// before
rank --market=hsa --limit=20
// after
rank --market=hs-a --limit=20
Defensive patterns

Strategy: validation

Validate before calling

const MARKETS = ['hs-a','sh-a','sz-a','bj-a','cyb','kcb','hk','us'];
const market = String(process.env.MARKET || 'hs-a').toLowerCase().trim();
if (!MARKETS.includes(market)) throw new Error(`market must be one of ${MARKETS.join(', ')}, got "${market}"`);

Type guard

const isValidMarket = (m) => ['hs-a','sh-a','sz-a','bj-a','cyb','kcb','hk','us'].includes(String(m).toLowerCase().trim());

Try / catch

try {
  await runRank(args);
} catch (e) {
  if (e.code === 'INVALID_ARGUMENT' && /Unknown market/.test(e.message)) {
    console.error(`${e.message} — see rank --help for the market list`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `eastmoney rank` with --market set to anything not in MARKETS: typos ('hsa', 'hs_a'), synonyms ('a-share', 'china', 'us-stock'), other rank variants' market names (e.g. markets from etf.js or convertible.js that don't exist here), or values like 'cyb ' with trailing whitespace inside the token (trim happens only via String().toLowerCase(), not trim).

Common situations: Copy-pasting market names from other eastmoney CLI commands or from web pages with different segment names; assuming aliases like 'a' or 'main' exist; shell scripts with stale or mistyped market variables; forgetting the value is matched exactly after lowercasing.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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