jackwener/OpenCLI · warning · CliError
INVALID_ARGUMENT
INVALID_ARGUMENT
Error message
Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(', ')} What it means
CliError with code INVALID_ARGUMENT thrown in etf.js's cli func (clis/eastmoney/etf.js:33) when the `--sort` value, lowercased, is not a key of that file's SORTS map. Like convertible.js's guard, it lists valid options in the message. Purely client-side validation; no request is sent. This is the ETF-listing CLI's analog of error 1336 with a different SORTS key set.
Source
Thrown at clis/eastmoney/etf.js:33
};
cli({
site: 'eastmoney',
name: 'etf',
access: 'read',
description: 'ETF 列表按成交额/涨跌幅排行',
domain: 'push2.eastmoney.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'sort', type: 'string', default: 'turnover', help: '排序:turnover / change / drop / volume / rate' },
{ name: 'limit', type: 'int', default: 20, help: '返回数量 (max 100)' },
],
columns: ['rank', 'code', 'name', 'price', 'changePercent', 'change', 'turnover', 'volume', 'turnoverRate'],
func: async (args) => {
const sortKey = String(args.sort ?? 'turnover').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', 'b:MK0021'); // 场内ETF
url.searchParams.set('fields', 'f12,f14,f2,f3,f4,f5,f6,f8');
url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');
const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
if (!resp.ok) throw new CliError('HTTP_ERROR', `etf failed: HTTP ${resp.status}`);
const data = await resp.json();
const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];View on GitHub (pinned to 49907e53dc)
Solutions
- Use a sort key listed in the error message from etf.js's SORTS map.
- Don't reuse convertible sort keys (premium/value/put-trigger) with the etf CLI — check each CLI's help for its own set.
- Fix typos and trim whitespace from the argument.
- Omit --sort to use the etf default (turnover).
- In scripts, validate the sort key against Object.keys(SORTS) before invoking.
Example fix
// before opencli eastmoney etf --sort premium // after opencli eastmoney etf --sort turnoverrate # or another key valid for etf
Defensive patterns
Strategy: validation
Validate before calling
// etf.js SORTS keys (from etf.js) — validate before invoking:
const etfSorts = ['turnover' /* ...see etf.js SORTS */];
const sortKey = String(sort ?? 'turnover').toLowerCase();
if (!etfSorts.includes(sortKey)) throw new Error(`etf --sort must be one of: ${etfSorts.join(', ')}`); Try / catch
try {
await run(['eastmoney', 'etf', '--sort', sortKey]);
} catch (e) {
if (e.code === 'INVALID_ARGUMENT' && String(e.message).startsWith('Unknown sort')) {
console.error(`bad --sort "${sortKey}"; falling back to default`);
await run(['eastmoney', 'etf']);
} else throw e;
} Prevention
- Use etf.js's own sort keys — do not copy convertible keys like premium/value/put-trigger.
- Check the INVALID_ARGUMENT code and message's valid-key list when handling programmatically.
- Trim/lowercase sort input before passing.
- Omit --sort to accept the turnover default.
- Keep per-CLI sort key references in scripts instead of sharing one constant.
When it happens
Trigger: Running `opencli eastmoney etf --sort premium` (a convertible-only key) or any key absent from etf's SORTS; misspellings; empty or whitespace-only values coerced to an unknown lowercase string; scripts passing programmatic sort names from another CLI's vocabulary.
Common situations: Copying the --sort flag values from the eastmoney convertible CLI into the etf CLI; typos like `turnoverr`; shell variables defaulting to invalid names; docs referencing sort keys removed in an earlier refactor.
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
- Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(
- coingecko limit must be a positive integer
- unknown mode "${mode}"
- Unknown tag: ${value}
- Unknown category: ${value}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ef598122fd0a87d0.
Report an issue: GitHub.