{"record":{"id":"ef598122fd0a87d0","repo":"jackwener/OpenCLI","slug":"invalid-argument-ef5981","errorCode":"INVALID_ARGUMENT","errorMessage":"Unknown sort \"${sortKey}\". Valid: ${Object.keys(SORTS).join(', ')}","messagePattern":"Unknown sort \"(.+?)\"\\. Valid: (.+?)","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"warning","filePath":"clis/eastmoney/etf.js","lineNumber":33,"sourceCode":"};\n\ncli({\n  site: 'eastmoney',\n  name: 'etf',\n    access: 'read',\n  description: 'ETF 列表按成交额/涨跌幅排行',\n  domain: 'push2.eastmoney.com',\n  strategy: Strategy.PUBLIC,\n  browser: false,\n  args: [\n    { name: 'sort', type: 'string', default: 'turnover', help: '排序：turnover / change / drop / volume / rate' },\n    { name: 'limit', type: 'int',   default: 20,         help: '返回数量 (max 100)' },\n  ],\n  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'change', 'turnover', 'volume', 'turnoverRate'],\n  func: async (args) => {\n    const sortKey = String(args.sort ?? 'turnover').toLowerCase();\n    const sort = SORTS[sortKey];\n    if (!sort) throw new CliError('INVALID_ARGUMENT', `Unknown sort \"${sortKey}\". Valid: ${Object.keys(SORTS).join(', ')}`);\n    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));\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', sort.order === 'desc' ? '1' : '0');\n    url.searchParams.set('np', '1');\n    url.searchParams.set('fltt', '2');\n    url.searchParams.set('invt', '2');\n    url.searchParams.set('fid', sort.fid);\n    url.searchParams.set('fs', 'b:MK0021'); // 场内ETF\n    url.searchParams.set('fields', 'f12,f14,f2,f3,f4,f5,f6,f8');\n    url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');\n\n    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n    if (!resp.ok) throw new CliError('HTTP_ERROR', `etf failed: HTTP ${resp.status}`);\n    const data = await resp.json();\n    const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/etf.js#L15-L51","documentation":"CliError with code INVALID_ARGUMENT thrown in etf.js's cli func (clis/eastmoney/etf.js:33) when the `--sort` value, lowercased, is not a key of that file's SORTS map. Like convertible.js's guard, it lists valid options in the message. Purely client-side validation; no request is sent. This is the ETF-listing CLI's analog of error 1336 with a different SORTS key set.","triggerScenarios":"Running `opencli eastmoney etf --sort premium` (a convertible-only key) or any key absent from etf's SORTS; misspellings; empty or whitespace-only values coerced to an unknown lowercase string; scripts passing programmatic sort names from another CLI's vocabulary.","commonSituations":"Copying the --sort flag values from the eastmoney convertible CLI into the etf CLI; typos like `turnoverr`; shell variables defaulting to invalid names; docs referencing sort keys removed in an earlier refactor.","solutions":["Use a sort key listed in the error message from etf.js's SORTS map.","Don't reuse convertible sort keys (premium/value/put-trigger) with the etf CLI — check each CLI's help for its own set.","Fix typos and trim whitespace from the argument.","Omit --sort to use the etf default (turnover).","In scripts, validate the sort key against Object.keys(SORTS) before invoking."],"exampleFix":"// before\nopencli eastmoney etf --sort premium\n// after\nopencli eastmoney etf --sort turnoverrate   # or another key valid for etf\n","handlingStrategy":"validation","validationCode":"// etf.js SORTS keys (from etf.js) — validate before invoking:\nconst etfSorts = ['turnover' /* ...see etf.js SORTS */];\nconst sortKey = String(sort ?? 'turnover').toLowerCase();\nif (!etfSorts.includes(sortKey)) throw new Error(`etf --sort must be one of: ${etfSorts.join(', ')}`);","typeGuard":null,"tryCatchPattern":"try {\n  await run(['eastmoney', 'etf', '--sort', sortKey]);\n} catch (e) {\n  if (e.code === 'INVALID_ARGUMENT' && String(e.message).startsWith('Unknown sort')) {\n    console.error(`bad --sort \"${sortKey}\"; falling back to default`);\n    await run(['eastmoney', 'etf']);\n  } else throw e;\n}","preventionTips":["Use etf.js's own sort keys — do not copy convertible keys like premium/value/put-trigger.","Check the INVALID_ARGUMENT code and message's valid-key list when handling programmatically.","Trim/lowercase sort input before passing.","Omit --sort to accept the turnover default.","Keep per-CLI sort key references in scripts instead of sharing one constant."],"tags":["cli","argument-validation","eastmoney","user-input"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}