jackwener/OpenCLI · error · CliError
INPUT_ERROR
INPUT_ERROR
Error message
Invalid market: "${market}" What it means
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.
Source
Thrown at clis/sinafinance/stock.js:75
description: '新浪财经行情(A股/港股/美股)',
domain: 'suggest3.sinajs.cn,hq.sinajs.cn',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'key', type: 'string', required: true, positional: true, help: 'Stock name or code (e.g. 贵州茅台, 腾讯控股, AAPL)' },
{ 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;View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
cli.stock({ key: 'AAPL', market: 'US' });
// after
cli.stock({ key: 'AAPL', market: 'us' }); Defensive patterns
Strategy: validation
Validate before calling
const VALID_MARKETS = ['cn', 'hk', 'us', 'auto'];
if (!VALID_MARKETS.includes(market)) {
throw new Error(`market must be one of ${VALID_MARKETS.join(', ')}; got "${market}"`);
} Type guard
function isValidMarket(m) {
return m === 'cn' || m === 'hk' || m === 'us' || m === 'auto';
} Try / catch
try {
const stock = await cli.stock({ key, market });
} catch (err) {
if (err.code === 'INPUT_ERROR' && /Invalid market/.test(err.message)) {
console.error('Use --market cn|hk|us|auto (lowercase)');
process.exitCode = 2;
return;
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Typing --market CN (uppercase) or --market china; shell scripts passing unvalidated variables into --market; users guessing supported market codes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/86aab147b924470f.
Report an issue: GitHub.