{"record":{"id":"1b286d889c9f8d84","repo":"jackwener/OpenCLI","slug":"invalid-argument-1b286d","errorCode":"INVALID_ARGUMENT","errorMessage":"Unknown group \"${group}\". Valid: main, hk, us, all","messagePattern":"Unknown group \"(.+?)\"\\. Valid: main, hk, us, all","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/eastmoney/index-board.js","lineNumber":60,"sourceCode":"  args: [\n    {\n      name: 'group',\n      type: 'string',\n      default: 'main',\n      help: '指数分组：main (A股主要), hk (港股), us (美股), all',\n    },\n  ],\n  columns: ['code', 'name', 'price', 'changePercent', 'change', 'open', 'high', 'low', 'prevClose'],\n  func: async (args) => {\n    const group = String(args.group ?? 'main').toLowerCase();\n    /** @type {[string,string][]} */\n    let entries;\n    if (group === 'all') {\n      entries = [...INDEX_GROUPS.main, ...INDEX_GROUPS.hk, ...INDEX_GROUPS.us];\n    } else if (INDEX_GROUPS[group]) {\n      entries = INDEX_GROUPS[group];\n    } else {\n      throw new CliError('INVALID_ARGUMENT', `Unknown group \"${group}\". Valid: main, hk, us, all`);\n    }\n\n    const secids = entries.map(([secid]) => secid).join(',');\n    const url = new URL('https://push2.eastmoney.com/api/qt/ulist.np/get');\n    url.searchParams.set('secids', secids);\n    url.searchParams.set('fltt', '2');\n    url.searchParams.set('fields', FIELDS);\n    url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');\n\n    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0', Accept: 'application/json' } });\n    if (!resp.ok) throw new CliError('HTTP_ERROR', `eastmoney index-board failed: HTTP ${resp.status}`);\n    const data = await resp.json();\n    const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];\n    if (diff.length === 0) throw new CliError('NO_DATA', 'eastmoney returned no index data');\n\n    // Preserve the order defined in INDEX_GROUPS regardless of API ordering\n    const byCode = new Map(diff.map((it) => [String(it.f12), it]));\n    return entries","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/index-board.js#L42-L78","documentation":"This CliError with code INVALID_ARGUMENT is thrown before any network call when the group argument is not one of the defined index groups. Valid values are exactly main, hk, us, or all (case-sensitive). The library uses INDEX_GROUPS as a lookup table and fails fast on unknown keys.","triggerScenarios":"Calling index-board with group values such as 'Main', 'MAIN', 'china', 'hs300', '', undefined-as-string, or any key absent from INDEX_GROUPS. Note 'Main' with different casing also fails because the lookup is case-sensitive.","commonSituations":"Typos or wrong casing in CLI flags/config files; passing a user-supplied group string without normalizing; documentation drift after group names changed between versions; scripts passing region names like 'asia' that never existed.","solutions":["Use one of the exact valid values: main, hk, us, or all","Normalize input first: group.trim().toLowerCase() before calling, keeping in mind only lowercase keys are valid","Check the CLI help / INDEX_GROUPS definition for the currently supported group names","Validate the group parameter in your own config loading and reject unknown values early"],"exampleFix":"// before\nawait indexBoard({ group: 'Main' }) // throws INVALID_ARGUMENT\n// after\nconst group = String(rawGroup ?? 'all').trim().toLowerCase();\nawait indexBoard({ group }) // 'main' | 'hk' | 'us' | 'all'","handlingStrategy":"validation","validationCode":"const VALID_GROUPS = new Set(['main', 'hk', 'us', 'all']);\nfunction validateGroup(group) {\n  const g = String(group ?? 'all').trim().toLowerCase();\n  if (!VALID_GROUPS.has(g)) {\n    throw new Error(`Unknown group \"${g}\". Valid: main, hk, us, all`);\n  }\n  return g;\n}","typeGuard":"function isValidGroup(g) {\n  return typeof g === 'string' && ['main', 'hk', 'us', 'all'].includes(g);\n}","tryCatchPattern":"try {\n  const board = await getIndexBoard({ group: validateGroup(userInput) });\n} catch (err) {\n  if (err.code === 'INVALID_ARGUMENT') {\n    console.error(`Bad group: ${err.message}. Defaulting to 'all'.`);\n    return getIndexBoard({ group: 'all' });\n  }\n  throw err;\n}","preventionTips":["Normalize and lowercase all group inputs before calling","Derive UI dropdown options from the library's valid values, not hardcoded strings","Validate config values at startup, before requests are made","Use TypeScript union types ('main' | 'hk' | 'us' | 'all') to catch mistakes at compile time"],"tags":["validation","invalid-argument","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}