jackwener/OpenCLI · warning · CliError

NOT_FOUND

NOT_FOUND

Error message

No stock found for "${key}"

What it means

This CliError with code NOT_FOUND is thrown after calling the sina suggest API when no stock entries match the user's search key in the requested markets. parseSuggest returned an empty array, meaning the suggest3.sinajs.cn endpoint returned no usable suggestions for the given key and target market list. It indicates a search-key/market mismatch rather than a network or parse failure.

Source

Thrown at clis/sinafinance/stock.js:81

        { name: 'market', type: 'string', default: 'auto', help: 'Market: cn, hk, us, auto (default: auto searches cn → hk → us)' },
    ],
    columns: ['Symbol', 'Name', 'Price', 'Change', 'ChangePercent', 'Open', 'High', 'Low', 'Volume', 'MarketCap'],
    func: async (args) => {
        const key = String(args.key);
        const market = String(args.market);
        const marketMap = {
            cn: [MARKET_CN], hk: [MARKET_HK], us: [MARKET_US],
            auto: [MARKET_CN, MARKET_HK, MARKET_US],
        };
        const targetMarkets = marketMap[market];
        if (!targetMarkets) {
            throw new CliError('INPUT_ERROR', `Invalid market: "${market}"`, 'Expected cn, hk, us, or auto');
        }
        // 1. Search symbol — only request the markets we care about
        const suggestRaw = await fetchGBK(`https://suggest3.sinajs.cn/suggest/type=${targetMarkets.join(',')}&key=${encodeURIComponent(key)}`);
        const entries = parseSuggest(suggestRaw, targetMarkets);
        if (!entries.length) {
            throw new CliError('NOT_FOUND', `No stock found for "${key}"`, 'Try a different name, code, or --market');
        }
        // Pick best match: score by name/symbol similarity, tiebreak by market priority
        const needle = key.toLowerCase();
        const score = (e) => {
            const n = e.name.toLowerCase();
            const s = e.symbol.toLowerCase();
            if (s === needle || n === needle)
                return 1;
            if (s.includes(needle))
                return needle.length / s.length;
            if (n.includes(needle))
                return needle.length / n.length;
            return 0;
        };
        const best = entries.sort((a, b) => {
            const d = score(b) - score(a);
            return d !== 0 ? d : targetMarkets.indexOf(a.market) - targetMarkets.indexOf(b.market);
        })[0];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run with a more accurate ticker code or full company name
  2. Remove the --market restriction or set it to 'auto' so all supported markets (cn, hk, us) are searched
  3. Try alternative spellings of the name (English vs Chinese vs pinyin) or the bare 6-digit code for CN stocks
  4. Verify the security still trades (not delisted/suspended) via another data source

Example fix

// before
stock 'PDD' --market cn   // no match in cn market
// after
stock 'PDD' --market us   # or omit --market to search all markets
Defensive patterns

Strategy: validation

Validate before calling

function looksLikeTickerOrCode(key) {
  return typeof key === 'string' && /^[A-Za-z0-9.一-龥]{2,20}$/.test(key.trim());
}
if (!looksLikeTickerOrCode(key)) throw new Error('Provide a valid stock code or name');

Type guard

const isSuggestEntry = (e) => typeof e?.symbol === 'string' && typeof e?.name === 'string' && typeof e?.market === 'string';

Try / catch

try {
  await stock(key, { market });
} catch (e) {
  if (e.code === 'NOT_FOUND') console.error(`No match for "${key}" — check spelling or try --market auto`);
  else throw e;
}

Prevention

When it happens

Trigger: Running the stock lookup CLI with a key that matches no symbol or company name on sina's suggest endpoint (typo, delisted stock, unsupported name), or restricting markets via --market to one where the stock is not listed so the filtered entries array is empty.

Common situations: Typing a pinyin/partial name the suggest API does not recognize; searching a US/HK ticker while --market is left as cn; searching an A-share code while forcing --market us; delisted or renamed securities; using a non-standard code format like '600000.SH' instead of the bare code.

Understand the failure class

Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.

Related errors


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