jackwener/OpenCLI · warning · CliError

INVALID_ARGUMENT

INVALID_ARGUMENT

Error message

`Unknown direction "${dir}". Valid: north / south`

What it means

The northbound command in clis/eastmoney/northbound.js validates the --direction argument against a whitelist of ['north','south','n','s'] (case-insensitive) before querying eastmoney's kamtbs.rtmin API. If the value is anything else, it throws this CliError with code INVALID_ARGUMENT. It is an input-validation guard so that an invalid direction never reaches an HTTP request.

Source

Thrown at clis/eastmoney/northbound.js:26

import { CliError } from '@jackwener/opencli/errors';

cli({
  site: 'eastmoney',
  name: 'northbound',
    access: 'read',
  description: '沪深港通北向/南向资金当日分时净流入(万元)',
  domain: 'push2.eastmoney.com',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'direction', type: 'string', default: 'north', help: '方向:north (北向,即外资买A) / south (南向,即内地买港)' },
    { name: 'limit',     type: 'int',    default: 10,      help: '返回最近 N 分钟' },
  ],
  columns: ['time', 'cumulativeNetYi', 'minuteNetYi', 'totalNetYi'],
  func: async (args) => {
    const dir = String(args.direction ?? 'north').toLowerCase();
    if (!['north', 'south', 'n', 's'].includes(dir)) {
      throw new CliError('INVALID_ARGUMENT', `Unknown direction "${dir}". Valid: north / south`);
    }
    const limit = Math.max(1, Math.min(Number(args.limit) || 10, 240));

    const url = new URL('https://push2.eastmoney.com/api/qt/kamtbs.rtmin/get');
    url.searchParams.set('fields1', 'f1,f2,f3,f4');
    url.searchParams.set('fields2', 'f51,f52,f54,f56');
    url.searchParams.set('ut', 'b2884a393a59ad64002292a3e90d46a5');

    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
    if (!resp.ok) throw new CliError('HTTP_ERROR', `northbound failed: HTTP ${resp.status}`);
    const data = await resp.json();
    const key = (dir === 'south' || dir === 's') ? 's2n' : 'n2s';
    /** @type {string[]} */
    const rows = Array.isArray(data?.data?.[key]) ? data.data[key] : [];
    if (rows.length === 0) throw new CliError('NO_DATA', `No ${key} data returned`);

    // CSV fields per entry: "HH:MM,cumulative_net(万), minute_net(万), total_net(万)"
    // Drop rows with '-' (after market close or before open). Convert 万元 → 亿元 for readability.

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the accepted values: north, south, n, or s (case-insensitive)
  2. Check the command help output for the exact valid values
  3. Remember 'n' means north (北向资金) and 's' means south (南向资金)
  4. If scripting, add shell-level validation before invoking the CLI

Example fix

// before
northbound --direction=northbound
// after
northbound --direction=north   # or 'n'
Defensive patterns

Strategy: validation

Validate before calling

const DIRS = ['north', 'south', 'n', 's'];
const dir = String(args.direction ?? 'north').toLowerCase();
if (!DIRS.includes(dir)) throw new Error(`direction must be one of ${DIRS.join('/')}, got "${dir}"`);

Type guard

const isDirection = (v) => ['north','south','n','s'].includes(String(v).toLowerCase());

Try / catch

try {
  await runNorthbound(args);
} catch (e) {
  if (e.code === 'INVALID_ARGUMENT') console.error(`Bad --direction: ${e.message}. Use north|south|n|s.`);
  else throw e;
}

Prevention

When it happens

Trigger: Calling the northbound CLI with --direction set to a value outside the whitelist, e.g. `--direction=up`, `--direction=northbound`, `--direction=南`, or a typo like `--direction=nort`. The value is lowercased before comparison, so only case differences are tolerated.

Common situations: Typing a plausible synonym ('northbound', '流入', 'in') that is not in the whitelist; copying examples from other tools that use different direction names; misspelling the flag value in scripts or shell aliases.

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