jackwener/OpenCLI · error · Error

empty symbol

Error message

empty symbol

What it means

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.

Source

Thrown at clis/eastmoney/_secid.js:37

 * Resolve various user inputs to an eastmoney `secid`.
 *  - "600000"         → "1.600000"
 *  - "sh600000"       → "1.600000"
 *  - "sz000001"       → "0.000001"
 *  - "bj430047"       → "0.430047"
 *  - "hk00700" / "00700.HK" → "116.00700"
 *  - "us.AAPL" / "AAPL" → "105.AAPL"
 *  - "1.600000"       → passed through
 * @param {string} input
 * @returns {string}
 */
// Known eastmoney market numeric prefixes. Narrow whitelist so that inputs like
// "00700.HK" are NOT mistakenly treated as secids just because they look like
// "<digits>.<alphanumeric>".
const KNOWN_MARKET_PREFIXES = new Set(['0', '1', '100', '105', '106', '107', '116', '140', '150', '151', '152', '155', '156']);

export function resolveSecid(input) {
  const raw = String(input || '').trim();
  if (!raw) throw new Error('empty symbol');
  const secidMatch = raw.match(/^(\d{1,3})\.([A-Za-z0-9]+)$/);
  if (secidMatch && KNOWN_MARKET_PREFIXES.has(secidMatch[1])) return raw; // already a secid
  const lower = raw.toLowerCase();

  // market-prefixed Chinese code
  const pref = lower.match(/^(sh|sz|bj)(\d{6})$/);
  if (pref) {
    const [, mk, code] = pref;
    return (mk === 'sh' ? '1' : '0') + '.' + code;
  }

  // hk prefix
  const hk = lower.match(/^hk(\d{4,5})$/) || lower.match(/^(\d{4,5})\.hk$/);
  if (hk) return '116.' + hk[1].padStart(5, '0');

  // us.SYMBOL or SYMBOL.N/.O  (treat all as NASDAQ by default; .N as NYSE)
  const usDot = lower.match(/^([a-z.\-]+)\.([no])$/);
  if (usDot) return (usDot[2] === 'n' ? '106' : '105') + '.' + usDot[1].toUpperCase();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty symbol string, e.g. resolveSecid('600519').
  2. Check the source variable for null/undefined/'' before calling and handle the missing-input case explicitly.
  3. If the value comes from env/config/argv, add a presence check with a clear user-facing message.

Example fix

// before
const secid = resolveSecid(process.env.TICKER);
// after
const ticker = process.env.TICKER?.trim();
if (!ticker) { console.error('TICKER env var is required'); process.exit(1); }
const secid = resolveSecid(ticker);
Defensive patterns

Strategy: validation

Validate before calling

function hasSymbol(v) { return typeof v === 'string' && v.trim().length > 0; }
if (!hasSymbol(input)) throw new Error('A non-empty symbol is required');

Type guard

const isNonEmptyString = (v) => typeof v === 'string' && v.trim() !== '';

Try / catch

try {
  const secid = resolveSecid(input);
} catch (e) {
  if (e.message === 'empty symbol') { /* missing input: prompt/log and skip */ }
  else throw e;
}

Prevention

When it happens

Trigger: Calling resolveSecid(''), resolveSecid(null), resolveSecid(undefined), or resolveSecid(' '); also any non-string falsy value like 0 or false, since String(input || '') yields ''.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/20db6e6bc98880a1. Report an issue: GitHub.