{"record":{"id":"ac6a5b4c1e4a0676","repo":"jackwener/OpenCLI","slug":"invalid-argument-ac6a5b","errorCode":"INVALID_ARGUMENT","errorMessage":"`Unknown range \"${rangeKey}\". Valid: ${Object.keys(RANGES).join(', ')}`","messagePattern":"`Unknown range \"(.+?)\"\\. Valid: (.+?)`","errorType":"validation","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/eastmoney/money-flow.js","lineNumber":36,"sourceCode":"cli({\n  site: 'eastmoney',\n  name: 'money-flow',\n    access: 'read',\n  description: '主力资金净流入排行（今日/5日/10日）',\n  domain: 'push2.eastmoney.com',\n  strategy: Strategy.PUBLIC,\n  browser: false,\n  args: [\n    { name: 'range', type: 'string', default: 'today', help: '周期：today / 5d / 10d' },\n    { name: 'order', type: 'string', default: 'desc', help: '排序：desc (净流入排行) / asc (净流出)' },\n    { name: 'limit', type: 'int', default: 20, help: '返回数量 (max 100)' },\n  ],\n  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'mainNet', 'mainNetRatio', 'superNet', 'bigNet', 'mediumNet', 'smallNet'],\n  func: async (args) => {\n    const rangeKey = String(args.range ?? 'today').toLowerCase();\n    const range = RANGES[rangeKey];\n    if (!range) {\n      throw new CliError('INVALID_ARGUMENT', `Unknown range \"${rangeKey}\". Valid: ${Object.keys(RANGES).join(', ')}`);\n    }\n    const po = String(args.order ?? 'desc').toLowerCase() === 'asc' ? '0' : '1';\n    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));\n\n    const fieldList = [\n      'f12', 'f14', 'f2', 'f3',\n      range.fields.net, range.fields.netPct,\n      range.fields.super, range.fields.big, range.fields.medium, range.fields.small,\n    ];\n\n    const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');\n    url.searchParams.set('pn', '1');\n    url.searchParams.set('pz', String(limit));\n    url.searchParams.set('po', po);\n    url.searchParams.set('np', '1');\n    url.searchParams.set('fltt', '2');\n    url.searchParams.set('invt', '2');\n    url.searchParams.set('fid', range.fid);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/money-flow.js#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Use one of the exact range keys listed in the error message (e.g. today); copy a valid key verbatim.","Check the RANGES object in clis/eastmoney/money-flow.js to see the authoritative set of accepted keys.","Trim whitespace from the value if it comes from a variable or environment setting.","Add the desired key to RANGES (name plus fid) if you need a range the CLI doesn't support, then rerun.","If generating calls programmatically, validate the range against Object.keys(RANGES) before invoking."],"exampleFix":"// before\nnode cli money-flow --range thisweek\n// CliError INVALID_ARGUMENT: Unknown range \"thisweek\". Valid: today, 3day, 5day, 10day\n// after\nnode cli money-flow --range 5day","handlingStrategy":"validation","validationCode":"const RANGES = ['today', '3day', '5day', '10day']; // mirror of Object.keys(RANGES) from the CLI\nconst range = String(args.range ?? 'today').toLowerCase().trim();\nif (!RANGES.includes(range)) throw new Error(`Invalid --range \"${range}\". Valid: ${RANGES.join(', ')}`);","typeGuard":null,"tryCatchPattern":"try {\n  await runMoneyFlow({ range: userRange });\n} catch (err) {\n  if (err instanceof CliError && err.code === 'INVALID_ARGUMENT') {\n    const valid = err.message.match(/Valid: (.+)$/)?.[1] ?? '';\n    console.error(`Bad --range. Accepted values: ${valid}`);\n    process.exitCode = 2; // usage error\n  } else throw err;\n}","preventionTips":["Copy range keys verbatim from the error's 'Valid:' list or the RANGES table in the source.","Never hardcode range strings in scripts; import or duplicate the RANGES key list and validate first.","Trim and lowercase user-supplied range values before passing them.","Document accepted range values where the CLI is invoked (CI configs, aliases, wrappers).","If a needed range is missing, add it to RANGES rather than passing an improvised value."],"tags":["validation","arguments","cli","eastmoney"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}