jackwener/OpenCLI · error · ArgumentError

--${name} must be a positive integer, got ${JSON.stringify(r

Error message

--${name} must be a positive integer, got ${JSON.stringify(raw)}

What it means

Thrown by parseStrictDecimalInteger in clis/ctrip/utils.js when a numeric option is neither an integer number nor a string of strict decimal digits. The library only accepts non-negative integers written without signs, decimals, or exponent notation, and rejects anything else with an ArgumentError quoting the raw value via JSON.stringify.

Source

Thrown at clis/ctrip/utils.js:21

 *
 * The single backing endpoint `https://m.ctrip.com/restapi/soa2/21881/json/gaHotelSearchEngine`
 * accepts a `searchType` discriminator:
 *   - `D` → destination suggest (cities, scenic spots, railway stations, landmarks)
 *   - `H` → hotel-context suggest (cities, business areas, individual hotels)
 *
 * Response shape is identical; we surface every field the endpoint emits as a
 * stable column so callers do not silently lose geo / English / id metadata.
 */
import { ArgumentError, CliError } from '@jackwener/opencli/errors';

const ENDPOINT = 'https://m.ctrip.com/restapi/soa2/21881/json/gaHotelSearchEngine';
const MIN_LIMIT = 1;
const MAX_LIMIT = 50;

function parseStrictDecimalInteger(name, raw) {
    if (typeof raw === 'number') {
        if (Number.isInteger(raw)) return raw;
        throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
    }
    if (typeof raw === 'string' && /^(0|[1-9]\d*)$/.test(raw)) {
        return Number(raw);
    }
    throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
}

export function parseStrictPositiveInteger(name, raw) {
    const parsed = parseStrictDecimalInteger(name, raw);
    if (parsed > 0) return parsed;
    throw new ArgumentError(`--${name} must be a positive integer, got ${JSON.stringify(raw)}`);
}

export function parseStrictIntegerRange(name, raw, fallback, min = MIN_LIMIT, max = MAX_LIMIT) {
    if (raw === undefined || raw === null || raw === '') return fallback;
    const parsed = parseStrictDecimalInteger(name, raw);
    if (parsed < min || parsed > max) {
        throw new ArgumentError(`--${name} must be between ${min} and ${max}, got ${parsed}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a plain non-negative integer, e.g. --limit 20.
  2. Strip whitespace and separators before passing programmatic values.
  3. Validate numeric CLI input in your wrapper script before invoking the command.

Example fix

// before
await run({ limit: '1,000' });
// after
await run({ limit: '50' });
Defensive patterns

Strategy: validation

Validate before calling

function isValidCount(v){ return typeof v === 'number' ? Number.isInteger(v) : typeof v === 'string' && /^(0|[1-9]\d*)$/.test(v); }

Type guard

const isStrictDecimalInt = (v) => (typeof v === 'number' && Number.isInteger(v)) || (typeof v === 'string' && /^(0|[1-9]\d*)$/.test(v));

Try / catch

try { await run(opts); } catch (e) { if (e instanceof ArgumentError && /positive integer/.test(e.message)) { console.error('Bad numeric flag:', e.message); } else throw e; }

Prevention

When it happens

Trigger: Passing --limit 2.5, --limit '1e2', --limit '-3', --limit '+5', --limit 'abc', or --limit ' 5 ' (whitespace) to any option routed through this parser.

Common situations: Shell variables containing floats or empty strings; users typing decimal limits; copy-pasted values with hidden whitespace or thousands separators like '1,000'.

Related errors


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