{"record":{"id":"6f8da00f21fa0791","repo":"jackwener/OpenCLI","slug":"invalid-argument-6f8da0","errorCode":"INVALID_ARGUMENT","errorMessage":"`Unknown market \"${market}\". Valid: ${Object.keys(MARKETS).join(', ')}`","messagePattern":"`Unknown market \"(.+?)\"\\. Valid: (.+?)`","errorType":"validation","errorClass":"CliError","httpStatus":null,"severity":"warning","filePath":"clis/eastmoney/rank.js","lineNumber":54,"sourceCode":"    access: 'read',\n  description: '东财市场涨跌/成交排行（沪深/北证/创/科/港/美）',\n  domain: 'push2.eastmoney.com',\n  strategy: Strategy.PUBLIC,\n  browser: false,\n  args: [\n    { name: 'market', type: 'string', default: 'hs-a', help: '市场：hs-a / sh-a / sz-a / bj-a / cyb / kcb / hk / us' },\n    { name: 'sort',   type: 'string', default: 'change', help: '排序：change / drop / turnover / volume / amplitude / rate' },\n    { name: 'limit',  type: 'int',    default: 20,       help: '返回数量 (max 100)' },\n  ],\n  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'change', 'turnover', 'volume', 'turnoverRate', 'peDynamic', 'marketCap'],\n  func: async (args) => {\n    const market = String(args.market ?? 'hs-a').toLowerCase();\n    const sortKey = String(args.sort ?? 'change').toLowerCase();\n    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));\n\n    const fs = MARKETS[market];\n    if (!fs) {\n      throw new CliError('INVALID_ARGUMENT', `Unknown market \"${market}\". Valid: ${Object.keys(MARKETS).join(', ')}`);\n    }\n    const sort = SORTS[sortKey];\n    if (!sort) {\n      throw new CliError('INVALID_ARGUMENT', `Unknown sort \"${sortKey}\". Valid: ${Object.keys(SORTS).join(', ')}`);\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', 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', fs);\n    url.searchParams.set('fields', FIELDS);\n    url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/rank.js#L36-L72","documentation":"The rank command validates --market against the MARKETS whitelist (hs-a, sh-a, sz-a, bj-a, cyb, kcb, hk, us). If the lowercased value has no entry, it throws CliError INVALID_ARGUMENT listing all valid keys. This guard prevents constructing a bogus fs (filter) parameter for the clist/get endpoint.","triggerScenarios":"Calling `eastmoney rank` with --market set to anything not in MARKETS: typos ('hsa', 'hs_a'), synonyms ('a-share', 'china', 'us-stock'), other rank variants' market names (e.g. markets from etf.js or convertible.js that don't exist here), or values like 'cyb ' with trailing whitespace inside the token (trim happens only via String().toLowerCase(), not trim).","commonSituations":"Copy-pasting market names from other eastmoney CLI commands or from web pages with different segment names; assuming aliases like 'a' or 'main' exist; shell scripts with stale or mistyped market variables; forgetting the value is matched exactly after lowercasing.","solutions":["Use one of the exact valid values: hs-a, sh-a, sz-a, bj-a, cyb, kcb, hk, us","Run `eastmoney rank --help` to see accepted market names","Lowercase and hyphenate: 'hs-a' not 'hsa' or 'HS A'","In scripts, validate the market variable against the same list before invoking"],"exampleFix":"// before\nrank --market=hsa --limit=20\n// after\nrank --market=hs-a --limit=20","handlingStrategy":"validation","validationCode":"const MARKETS = ['hs-a','sh-a','sz-a','bj-a','cyb','kcb','hk','us'];\nconst market = String(process.env.MARKET || 'hs-a').toLowerCase().trim();\nif (!MARKETS.includes(market)) throw new Error(`market must be one of ${MARKETS.join(', ')}, got \"${market}\"`);","typeGuard":"const isValidMarket = (m) => ['hs-a','sh-a','sz-a','bj-a','cyb','kcb','hk','us'].includes(String(m).toLowerCase().trim());","tryCatchPattern":"try {\n  await runRank(args);\n} catch (e) {\n  if (e.code === 'INVALID_ARGUMENT' && /Unknown market/.test(e.message)) {\n    console.error(`${e.message} — see rank --help for the market list`);\n  } else throw e;\n}","preventionTips":["Copy market names exactly from --help output, hyphens included (hs-a, sh-a)","Lowercase and trim variables before passing them","Do not assume aliases ('a', 'main', 'us-stock') exist — only the 8 listed keys","Keep a shared constant of valid market names in your tooling"],"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"}