{"record":{"id":"86aab147b924470f","repo":"jackwener/OpenCLI","slug":"input-error","errorCode":"INPUT_ERROR","errorMessage":"Invalid market: \"${market}\"","messagePattern":"Invalid market: \"(.+?)\"","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/sinafinance/stock.js","lineNumber":75,"sourceCode":"    description: '新浪财经行情（A股/港股/美股）',\n    domain: 'suggest3.sinajs.cn,hq.sinajs.cn',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'key', type: 'string', required: true, positional: true, help: 'Stock name or code (e.g. 贵州茅台, 腾讯控股, AAPL)' },\n        { name: 'market', type: 'string', default: 'auto', help: 'Market: cn, hk, us, auto (default: auto searches cn → hk → us)' },\n    ],\n    columns: ['Symbol', 'Name', 'Price', 'Change', 'ChangePercent', 'Open', 'High', 'Low', 'Volume', 'MarketCap'],\n    func: async (args) => {\n        const key = String(args.key);\n        const market = String(args.market);\n        const marketMap = {\n            cn: [MARKET_CN], hk: [MARKET_HK], us: [MARKET_US],\n            auto: [MARKET_CN, MARKET_HK, MARKET_US],\n        };\n        const targetMarkets = marketMap[market];\n        if (!targetMarkets) {\n            throw new CliError('INPUT_ERROR', `Invalid market: \"${market}\"`, 'Expected cn, hk, us, or auto');\n        }\n        // 1. Search symbol — only request the markets we care about\n        const suggestRaw = await fetchGBK(`https://suggest3.sinajs.cn/suggest/type=${targetMarkets.join(',')}&key=${encodeURIComponent(key)}`);\n        const entries = parseSuggest(suggestRaw, targetMarkets);\n        if (!entries.length) {\n            throw new CliError('NOT_FOUND', `No stock found for \"${key}\"`, 'Try a different name, code, or --market');\n        }\n        // Pick best match: score by name/symbol similarity, tiebreak by market priority\n        const needle = key.toLowerCase();\n        const score = (e) => {\n            const n = e.name.toLowerCase();\n            const s = e.symbol.toLowerCase();\n            if (s === needle || n === needle)\n                return 1;\n            if (s.includes(needle))\n                return needle.length / s.length;\n            if (n.includes(needle))\n                return needle.length / n.length;","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/sinafinance/stock.js#L57-L93","documentation":"CliError with code INPUT_ERROR thrown when the --market option is not one of cn, hk, us, or auto. The invalid value is interpolated. This is a pure user-input validation error, thrown before any network call.","triggerScenarios":"Passing --market with a value like 'CN', 'china', 'sh', or any string not exactly matching the marketMap keys (cn, hk, us, auto). The lookup is case-sensitive and exact.","commonSituations":"Typing --market CN (uppercase) or --market china; shell scripts passing unvalidated variables into --market; users guessing supported market codes.","solutions":["Use one of the exact accepted values: cn, hk, us, or auto","Use auto when unsure which market the symbol belongs to","Fix case — values are lowercase only","Validate market strings in scripts before passing them to the CLI"],"exampleFix":"// before\ncli.stock({ key: 'AAPL', market: 'US' });\n// after\ncli.stock({ key: 'AAPL', market: 'us' });","handlingStrategy":"validation","validationCode":"const VALID_MARKETS = ['cn', 'hk', 'us', 'auto'];\nif (!VALID_MARKETS.includes(market)) {\n  throw new Error(`market must be one of ${VALID_MARKETS.join(', ')}; got \"${market}\"`);\n}","typeGuard":"function isValidMarket(m) {\n  return m === 'cn' || m === 'hk' || m === 'us' || m === 'auto';\n}","tryCatchPattern":"try {\n  const stock = await cli.stock({ key, market });\n} catch (err) {\n  if (err.code === 'INPUT_ERROR' && /Invalid market/.test(err.message)) {\n    console.error('Use --market cn|hk|us|auto (lowercase)');\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Validate the market value against cn/hk/us/auto before calling","Remember the values are lowercase and case-sensitive","Default to 'auto' when the market is unknown","Sanitize CLI flags in shell scripts to avoid stray whitespace/case"],"tags":["input-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"}