{"record":{"id":"9663716b89c9adb8","repo":"jackwener/OpenCLI","slug":"invalid-argument-966371","errorCode":"INVALID_ARGUMENT","errorMessage":"`Unknown direction \"${dir}\". Valid: north / south`","messagePattern":"`Unknown direction \"(.+?)\"\\. Valid: north / south`","errorType":"validation","errorClass":"CliError","httpStatus":null,"severity":"warning","filePath":"clis/eastmoney/northbound.js","lineNumber":26,"sourceCode":"import { CliError } from '@jackwener/opencli/errors';\n\ncli({\n  site: 'eastmoney',\n  name: 'northbound',\n    access: 'read',\n  description: '沪深港通北向/南向资金当日分时净流入（万元）',\n  domain: 'push2.eastmoney.com',\n  strategy: Strategy.PUBLIC,\n  browser: false,\n  args: [\n    { name: 'direction', type: 'string', default: 'north', help: '方向：north (北向，即外资买A) / south (南向，即内地买港)' },\n    { name: 'limit',     type: 'int',    default: 10,      help: '返回最近 N 分钟' },\n  ],\n  columns: ['time', 'cumulativeNetYi', 'minuteNetYi', 'totalNetYi'],\n  func: async (args) => {\n    const dir = String(args.direction ?? 'north').toLowerCase();\n    if (!['north', 'south', 'n', 's'].includes(dir)) {\n      throw new CliError('INVALID_ARGUMENT', `Unknown direction \"${dir}\". Valid: north / south`);\n    }\n    const limit = Math.max(1, Math.min(Number(args.limit) || 10, 240));\n\n    const url = new URL('https://push2.eastmoney.com/api/qt/kamtbs.rtmin/get');\n    url.searchParams.set('fields1', 'f1,f2,f3,f4');\n    url.searchParams.set('fields2', 'f51,f52,f54,f56');\n    url.searchParams.set('ut', 'b2884a393a59ad64002292a3e90d46a5');\n\n    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n    if (!resp.ok) throw new CliError('HTTP_ERROR', `northbound failed: HTTP ${resp.status}`);\n    const data = await resp.json();\n    const key = (dir === 'south' || dir === 's') ? 's2n' : 'n2s';\n    /** @type {string[]} */\n    const rows = Array.isArray(data?.data?.[key]) ? data.data[key] : [];\n    if (rows.length === 0) throw new CliError('NO_DATA', `No ${key} data returned`);\n\n    // CSV fields per entry: \"HH:MM,cumulative_net(万), minute_net(万), total_net(万)\"\n    // Drop rows with '-' (after market close or before open). Convert 万元 → 亿元 for readability.","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/northbound.js#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use one of the accepted values: north, south, n, or s (case-insensitive)","Check the command help output for the exact valid values","Remember 'n' means north (北向资金) and 's' means south (南向资金)","If scripting, add shell-level validation before invoking the CLI"],"exampleFix":"// before\nnorthbound --direction=northbound\n// after\nnorthbound --direction=north   # or 'n'","handlingStrategy":"validation","validationCode":"const DIRS = ['north', 'south', 'n', 's'];\nconst dir = String(args.direction ?? 'north').toLowerCase();\nif (!DIRS.includes(dir)) throw new Error(`direction must be one of ${DIRS.join('/')}, got \"${dir}\"`);","typeGuard":"const isDirection = (v) => ['north','south','n','s'].includes(String(v).toLowerCase());","tryCatchPattern":"try {\n  await runNorthbound(args);\n} catch (e) {\n  if (e.code === 'INVALID_ARGUMENT') console.error(`Bad --direction: ${e.message}. Use north|south|n|s.`);\n  else throw e;\n}","preventionTips":["Always use the canonical values north/south/n/s in scripts","Remember only case differences are normalized — spelling must match exactly","Check --help output before scripting against a new CLI command"],"tags":["cli","argument-validation","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}