jackwener/OpenCLI · error · ArgumentError

limit must be an integer between 1 and 15 (dianping single p

Error message

limit must be an integer between 1 and 15 (dianping single page)

What it means

requireSearchLimit validates the search limit against dianping's single-page constraint: the PC search page returns at most 15 results per request, so limits must be integers from 1 to 15. Non-integers (including strings that parse to non-integers or NaN), zero, negatives, and values above 15 all throw this ArgumentError. An empty/missing value defaults to 15.

Source

Thrown at clis/dianping/utils.js:71

    if (cityArg == null || cityArg === '') return null;
    const raw = String(cityArg).trim().toLowerCase();
    if (/^\d+$/.test(raw)) return Number(raw);
    const id = CITY_ID[raw];
    if (!id) {
        const names = Object.keys(CITY_ID).filter((k) => /^[a-z]+$/.test(k)).join(', ');
        throw new ArgumentError(
            'city',
            `unknown city '${cityArg}'. pass a numeric cityId or one of: ${names}`,
        );
    }
    return id;
}

export function requireSearchLimit(value) {
    const raw = value == null || value === '' ? 15 : value;
    const limit = typeof raw === 'number' ? raw : Number(String(raw).trim());
    if (!Number.isInteger(limit) || limit < 1 || limit > 15) {
        throw new ArgumentError('limit must be an integer between 1 and 15 (dianping single page)');
    }
    return limit;
}

export function normalizeShopId(rawInput) {
    const raw = String(rawInput || '').trim();
    if (!raw) throw new ArgumentError('shop_id must be a non-empty string');

    const idMatch = raw.match(/\/shop\/([^?#/]+)/);
    const shopId = idMatch ? idMatch[1] : raw;
    if (!/^[A-Za-z0-9_-]+$/.test(shopId)) {
        throw new ArgumentError(`'${raw}' does not look like a dianping shop id`);
    }
    return shopId;
}

export function wrapDianpingStep(label, fn) {
    return Promise.resolve()

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use an integer between 1 and 15; omit the flag entirely to get the default of 15.
  2. If you need more than 15 results, run multiple searches (e.g. vary keyword or page/city offsets) and merge the rows yourself.
  3. Coerce and clamp the value before calling: Math.min(15, Math.max(1, Math.round(Number(raw)))).
  4. Validate the config/CLI input source so it cannot supply non-numeric text.

Example fix

// before
requireSearchLimit('20'); // ArgumentError
// after
const n = Math.min(15, Math.max(1, Math.round(Number(raw))));
requireSearchLimit(n); // ok, capped to 15
Defensive patterns

Strategy: validation

Validate before calling

function isValidLimit(v) {
  if (v == null || v === '') return true; // defaults to 15
  const n = typeof v === 'number' ? v : Number(String(v).trim());
  return Number.isInteger(n) && n >= 1 && n <= 15;
}

Type guard

function isSearchLimit(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 15;
}

Try / catch

try {
  const limit = requireSearchLimit(rawLimit);
} catch (e) {
  if (e.name === 'ArgumentError' && /between 1 and 15/.test(e.message)) {
    console.error(`limit '${rawLimit}' invalid; clamping to default range 1-15`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing limit=16 or higher (e.g. expecting pagination to be automatic), passing limit=0 or a negative number, passing a non-numeric string like 'all' or '10个', or a decimal like 2.5.

Common situations: Assuming the CLI paginates automatically for larger limits; copying a limit from another API that allows 50/100; CLI flag passed as free text; script reading limit from config where it was stored as '20'.

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/97ebb810cb0b2ec3. Report an issue: GitHub.