{"record":{"id":"20db6e6bc98880a1","repo":"jackwener/OpenCLI","slug":"empty-symbol","errorCode":null,"errorMessage":"empty symbol","messagePattern":"empty symbol","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/eastmoney/_secid.js","lineNumber":37,"sourceCode":" * Resolve various user inputs to an eastmoney `secid`.\n *  - \"600000\"         → \"1.600000\"\n *  - \"sh600000\"       → \"1.600000\"\n *  - \"sz000001\"       → \"0.000001\"\n *  - \"bj430047\"       → \"0.430047\"\n *  - \"hk00700\" / \"00700.HK\" → \"116.00700\"\n *  - \"us.AAPL\" / \"AAPL\" → \"105.AAPL\"\n *  - \"1.600000\"       → passed through\n * @param {string} input\n * @returns {string}\n */\n// Known eastmoney market numeric prefixes. Narrow whitelist so that inputs like\n// \"00700.HK\" are NOT mistakenly treated as secids just because they look like\n// \"<digits>.<alphanumeric>\".\nconst KNOWN_MARKET_PREFIXES = new Set(['0', '1', '100', '105', '106', '107', '116', '140', '150', '151', '152', '155', '156']);\n\nexport function resolveSecid(input) {\n  const raw = String(input || '').trim();\n  if (!raw) throw new Error('empty symbol');\n  const secidMatch = raw.match(/^(\\d{1,3})\\.([A-Za-z0-9]+)$/);\n  if (secidMatch && KNOWN_MARKET_PREFIXES.has(secidMatch[1])) return raw; // already a secid\n  const lower = raw.toLowerCase();\n\n  // market-prefixed Chinese code\n  const pref = lower.match(/^(sh|sz|bj)(\\d{6})$/);\n  if (pref) {\n    const [, mk, code] = pref;\n    return (mk === 'sh' ? '1' : '0') + '.' + code;\n  }\n\n  // hk prefix\n  const hk = lower.match(/^hk(\\d{4,5})$/) || lower.match(/^(\\d{4,5})\\.hk$/);\n  if (hk) return '116.' + hk[1].padStart(5, '0');\n\n  // us.SYMBOL or SYMBOL.N/.O  (treat all as NASDAQ by default; .N as NYSE)\n  const usDot = lower.match(/^([a-z.\\-]+)\\.([no])$/);\n  if (usDot) return (usDot[2] === 'n' ? '106' : '105') + '.' + usDot[1].toUpperCase();","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/_secid.js#L19-L55","documentation":"resolveSecid() converts a user symbol (e.g. '600519', 'sh600519', 'AAPL', '00700.HK'-style strings) into an Eastmoney secid ('market.code'). It throws 'empty symbol' when the input, after String() coercion and trimming, is an empty string — i.e. nothing usable was passed.","triggerScenarios":"Calling resolveSecid(''), resolveSecid(null), resolveSecid(undefined), or resolveSecid('   '); also any non-string falsy value like 0 or false, since String(input || '') yields ''.","commonSituations":"An env var or config key for the ticker is unset; a CLI flag was omitted and defaults to ''; an upstream lookup returned null/undefined before being passed in.","solutions":["Pass a non-empty symbol string, e.g. resolveSecid('600519').","Check the source variable for null/undefined/'' before calling and handle the missing-input case explicitly.","If the value comes from env/config/argv, add a presence check with a clear user-facing message."],"exampleFix":"// before\nconst secid = resolveSecid(process.env.TICKER);\n// after\nconst ticker = process.env.TICKER?.trim();\nif (!ticker) { console.error('TICKER env var is required'); process.exit(1); }\nconst secid = resolveSecid(ticker);","handlingStrategy":"validation","validationCode":"function hasSymbol(v) { return typeof v === 'string' && v.trim().length > 0; }\nif (!hasSymbol(input)) throw new Error('A non-empty symbol is required');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim() !== '';","tryCatchPattern":"try {\n  const secid = resolveSecid(input);\n} catch (e) {\n  if (e.message === 'empty symbol') { /* missing input: prompt/log and skip */ }\n  else throw e;\n}","preventionTips":["Trim and check user/config/env input before calling resolveSecid","Give CLI flags explicit required-argument errors instead of defaulting to ''","Centralize symbol input parsing in one guarded helper"],"tags":["validation","input","secid"],"backgroundTag":"empty-required-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}