jackwener/OpenCLI · warning · CliError

INVALID_ARGUMENT

INVALID_ARGUMENT

Error message

--limit must be a positive integer no greater than 100

What it means

parseLimit validates the --limit option for the ths hot-rank CLI. It must be an integer in 1..100 (defaulting to 20); anything else throws CliError with code INVALID_ARGUMENT. This fails fast on bad user input before any network call.

Source

Thrown at clis/ths/hot-rank.js:17

import { cli, Strategy } from '@jackwener/opencli/registry';
import { CliError } from '@jackwener/opencli/errors';

const THS_HOT_API_URL = 'https://dq.10jqka.com.cn/fuyao/hot_list_data/out/hot_list/v1/stock?stock_type=a&type=hour&list_type=normal';

function tagsFromStock(stock) {
  const tag = stock?.tag && typeof stock.tag === 'object' ? stock.tag : {};
  return [
    ...(Array.isArray(tag.concept_tag) ? tag.concept_tag : []),
    ...(Array.isArray(tag.popularity_tag) ? tag.popularity_tag : []),
  ].filter(Boolean).join(',');
}

function parseLimit(raw) {
  const limit = Number(raw ?? 20);
  if (!Number.isInteger(limit) || limit <= 0 || limit > 100) {
    throw new CliError('INVALID_ARGUMENT', '--limit must be a positive integer no greater than 100');
  }
  return limit;
}

cli({
  site: 'ths',
  name: 'hot-rank',
    access: 'read',
  description: '同花顺热股榜',
  domain: 'dq.10jqka.com.cn',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'limit', type: 'int', default: 20, help: '返回数量' },
  ],
  columns: ['rank', 'name', 'changePercent', 'heat', 'tags'],
  func: async (args) => {
    const limit = parseLimit(args.limit);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 100, e.g. --limit 50
  2. Omit --limit entirely to use the default of 20
  3. Quote/validate the value in shell scripts before interpolation
  4. Clamp user-supplied input in your wrapper before invoking the CLI

Example fix

// before
ths hot-rank --limit 250
// after
ths hot-rank --limit 100
Defensive patterns

Strategy: validation

Validate before calling

function coerceLimit(raw, { min = 1, max = 100, dflt = 20 } = {}) {
  const n = Number(raw ?? dflt);
  if (!Number.isInteger(n) || n < min || n > max) return dflt;
  return n;
}
const limit = coerceLimit(process.env.LIMIT ?? cliArgs.limit);

Type guard

function isValidLimit(v) {
  return Number.isInteger(v) && v > 0 && v <= 100;
}

Try / catch

try {
  await thsHotRank({ limit });
} catch (e) {
  if (e?.code === 'INVALID_ARGUMENT') {
    console.error('Usage: --limit <1-100 integer>');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --limit as 0, negative, >100, or a non-integer/non-numeric string (e.g. 'abc', '2.5', '0', '101'). Number(raw ?? 20) coerces, so '' becomes 0 and 'all' becomes NaN — both invalid.

Common situations: User typos a value over the API cap (ths rank API returns at most ~100 rows); passing '10%' or 'top10'; shell scripts interpolating empty variables.

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


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