jackwener/OpenCLI · error · CliError

INVALID_ARGUMENT

INVALID_ARGUMENT

Error message

`Unknown sector type "${typeKey}". Valid: ${Object.keys(SECTOR_TYPES).join(', ')}`

What it means

The eastmoney sectors CLI validates the --type argument against the SECTOR_TYPES lookup table before building the API query. If the lowercased type key is not found, it throws INVALID_ARGUMENT listing the valid keys. This is a client-side input validation error; no network request is made.

Source

Thrown at clis/eastmoney/sectors.js:40

cli({
  site: 'eastmoney',
  name: 'sectors',
    access: 'read',
  description: '板块排行(行业/概念/地域)按涨跌幅、主力资金或成交额排序',
  domain: 'push2.eastmoney.com',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'type', type: 'string', default: 'industry', help: '板块类型:industry / concept / region' },
    { name: 'sort', type: 'string', default: 'change',   help: '排序:change / drop / money-flow / out-flow / turnover' },
    { name: 'limit', type: 'int',   default: 20,         help: '返回数量 (max 100)' },
  ],
  columns: ['rank', 'code', 'name', 'price', 'changePercent', 'mainNet', 'leadStock', 'leadChangePercent', 'upCount', 'downCount'],
  func: async (args) => {
    const typeKey = String(args.type ?? 'industry').toLowerCase();
    const fs = SECTOR_TYPES[typeKey];
    if (!fs) throw new CliError('INVALID_ARGUMENT', `Unknown sector type "${typeKey}". Valid: ${Object.keys(SECTOR_TYPES).join(', ')}`);
    const sortKey = String(args.sort ?? 'change').toLowerCase();
    const sort = SORTS[sortKey];
    if (!sort) throw new CliError('INVALID_ARGUMENT', `Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(', ')}`);
    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));

    const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');
    url.searchParams.set('pn', '1');
    url.searchParams.set('pz', String(limit));
    url.searchParams.set('po', sort.order === 'desc' ? '1' : '0');
    url.searchParams.set('np', '1');
    url.searchParams.set('fltt', '2');
    url.searchParams.set('invt', '2');
    url.searchParams.set('fid', sort.fid);
    url.searchParams.set('fs', fs);
    url.searchParams.set('fields', 'f12,f14,f2,f3,f62,f104,f105,f128,f136,f140,f141');
    url.searchParams.set('ut', 'b2884a393a59ad64002292a3e90d46a5');

    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the valid types listed in the error message (e.g. industry, concept)
  2. Run the command with the default (omit --type) to get industry sectors
  3. Check the CLI help output for the supported type values
  4. Fix the calling script to pass a whitelisted type key

Example fix

// before
sectors({ type: 'ind' });
// after
sectors({ type: 'industry' });
Defensive patterns

Strategy: validation

Validate before calling

const SECTOR_TYPES = ['industry','concept'];
const type = String(args.type ?? 'industry').toLowerCase();
if (!SECTOR_TYPES.includes(type)) throw new Error(`type must be one of: ${SECTOR_TYPES.join(', ')}`);

Try / catch

try {
  await sectors({ type });
} catch (e) {
  if (e.code === 'INVALID_ARGUMENT') console.error('Bad --type:', e.message);
  else throw e;
}

Prevention

When it happens

Trigger: Running the sectors command with --type set to a value not in SECTOR_TYPES, e.g. --type sector or --type ind instead of a valid key like industry or concept.

Common situations: Typo in the type flag, translating/abbreviating type names, scripts passing a free-form category name from another tool, case-sensitive assumptions (though the CLI lowercases input).

Related errors


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