jackwener/OpenCLI · error · ArgumentError

semanticscholar ${label} must be <= ${maxValue}

Error message

semanticscholar ${label} must be <= ${maxValue}

What it means

requireBoundedInt enforces an upper bound on integer arguments (label defaults to 'limit'): when the value exceeds maxValue (e.g. 100 for search), it throws ArgumentError naming the cap. The bound mirrors what the Semantic Scholar API accepts per page so requests are never rejected upstream.

Source

Thrown at clis/semanticscholar/utils.js:41

// Other Semantic Scholar accepted prefixes that we pass through verbatim.
const PREFIXED = /^(ARXIV|MAG|ACL|PMID|PMCID|URL|CorpusId|DBLP):/i;

export function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) {
        throw new ArgumentError(`semanticscholar ${label} cannot be empty`);
    }
    return s;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`semanticscholar ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`semanticscholar ${label} must be <= ${maxValue}`);
    }
    return n;
}

/**
 * Resolve a user-supplied paper reference to a Semantic Scholar paper id
 * segment. Accepts:
 *
 *   - bare Semantic Scholar paperId (40-char hex)
 *   - DOI (with or without `doi:` / `https://doi.org/` prefix)
 *   - arXiv id (`1706.03762` / `1706.03762v3` / `cs/0501067`)
 *   - typed prefixes Semantic Scholar accepts verbatim (`ARXIV:`, `MAG:`,
 *     `ACL:`, `PMID:`, `PMCID:`, `URL:`, `CorpusId:`, `DBLP:`)
 *   - full `https://www.semanticscholar.org/paper/<paperId>` URL
 */
export function requirePaperRef(value) {
    const raw = String(value ?? '').trim();
    if (!raw) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower the value to the cap (e.g. `--limit 100` for search).
  2. Paginate: issue multiple requests with offset to retrieve more results.
  3. Clamp programmatically: `const lim = Math.min(requested, 100);`

Example fix

// before
const limit = requireBoundedInt(args.limit, 20, 100); // throws for 500
// after
const limit = requireBoundedInt(Math.min(Number(args.limit) || 20, 100), 20, 100);
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 100;
const requested = Number(args.limit ?? 20);
if (requested > MAX) throw new Error(`--limit must be <= ${MAX}; paginate with offset instead`);

Type guard

function isWithinBound(n, max) { return Number.isInteger(n) && n > 0 && n <= max; }

Try / catch

try {
    await runSearch({ limit });
} catch (err) {
    if (err instanceof ArgumentError && /must be <=/.test(err.message)) {
        console.error(`${err.message}; use multiple requests with offset to page through results.`);
        process.exit(2);
    }
    throw err;
}

Prevention

When it happens

Trigger: Passing `--limit 101` or higher to search (max 100), or exceeding any other labeled maxValue; scripts generating page sizes above the cap.

Common situations: Users trying to 'fetch everything' with a huge limit instead of paginating; hardcoded constants copied from APIs with higher caps; loops adding offset without respecting per-request limits.

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