jackwener/OpenCLI · error · CliError

INVALID_ARGUMENT

INVALID_ARGUMENT

Error message

`Unknown range "${rangeKey}". Valid: ${Object.keys(RANGES).join(', ')}`

What it means

The eastmoney money-flow CLI throws CliError('INVALID_ARGUMENT') when the `--range` argument does not match any key in the RANGES lookup table. RANGES maps user-facing range names (e.g. 'today') to the fid sort field used by the push2 API. The message lists all valid keys so the caller can immediately see accepted values.

Source

Thrown at clis/eastmoney/money-flow.js:36

cli({
  site: 'eastmoney',
  name: 'money-flow',
    access: 'read',
  description: '主力资金净流入排行(今日/5日/10日)',
  domain: 'push2.eastmoney.com',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'range', type: 'string', default: 'today', help: '周期:today / 5d / 10d' },
    { name: 'order', type: 'string', default: 'desc', help: '排序:desc (净流入排行) / asc (净流出)' },
    { name: 'limit', type: 'int', default: 20, help: '返回数量 (max 100)' },
  ],
  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'mainNet', 'mainNetRatio', 'superNet', 'bigNet', 'mediumNet', 'smallNet'],
  func: async (args) => {
    const rangeKey = String(args.range ?? 'today').toLowerCase();
    const range = RANGES[rangeKey];
    if (!range) {
      throw new CliError('INVALID_ARGUMENT', `Unknown range "${rangeKey}". Valid: ${Object.keys(RANGES).join(', ')}`);
    }
    const po = String(args.order ?? 'desc').toLowerCase() === 'asc' ? '0' : '1';
    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));

    const fieldList = [
      'f12', 'f14', 'f2', 'f3',
      range.fields.net, range.fields.netPct,
      range.fields.super, range.fields.big, range.fields.medium, range.fields.small,
    ];

    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', po);
    url.searchParams.set('np', '1');
    url.searchParams.set('fltt', '2');
    url.searchParams.set('invt', '2');
    url.searchParams.set('fid', range.fid);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the exact range keys listed in the error message (e.g. today); copy a valid key verbatim.
  2. Check the RANGES object in clis/eastmoney/money-flow.js to see the authoritative set of accepted keys.
  3. Trim whitespace from the value if it comes from a variable or environment setting.
  4. Add the desired key to RANGES (name plus fid) if you need a range the CLI doesn't support, then rerun.
  5. If generating calls programmatically, validate the range against Object.keys(RANGES) before invoking.

Example fix

// before
node cli money-flow --range thisweek
// CliError INVALID_ARGUMENT: Unknown range "thisweek". Valid: today, 3day, 5day, 10day
// after
node cli money-flow --range 5day
Defensive patterns

Strategy: validation

Validate before calling

const RANGES = ['today', '3day', '5day', '10day']; // mirror of Object.keys(RANGES) from the CLI
const range = String(args.range ?? 'today').toLowerCase().trim();
if (!RANGES.includes(range)) throw new Error(`Invalid --range "${range}". Valid: ${RANGES.join(', ')}`);

Try / catch

try {
  await runMoneyFlow({ range: userRange });
} catch (err) {
  if (err instanceof CliError && err.code === 'INVALID_ARGUMENT') {
    const valid = err.message.match(/Valid: (.+)$/)?.[1] ?? '';
    console.error(`Bad --range. Accepted values: ${valid}`);
    process.exitCode = 2; // usage error
  } else throw err;
}

Prevention

When it happens

Trigger: Passing `--range` (or args.range) with a value that is not a key of RANGES after lowercasing and defaulting — e.g. `--range thisweek` when the table defines 'week', a typo like `--range tody`, or an untrimmed value with whitespace. Note the default is 'today', so omitting the flag is safe.

Common situations: Typos or guessing range names from memory; assuming a range alias exists ('daily', '7d', 'month-to-date') that the CLI never defined; script variables built by string concatenation producing values like 'last_week'; case issues in shells that pass the flag already uppercased (handled by toLowerCase, but not whitespace).

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/ac6a5b4c1e4a0676. Report an issue: GitHub.