jackwener/OpenCLI · error · ArgumentError
wikidata must be <=
Error message
wikidata ${label} must be <= ${maxValue} What it means
requireBoundedInt enforces an upper bound on numeric options like limit. Once the value is confirmed to be a positive integer, it throws an ArgumentError if it exceeds the adapter's configured maximum for that option. This protects the Wikidata API (and response size) from unbounded requests.
Solutions
- Lower the limit to the documented maximum for the command (check --help for the cap)
- Clamp the value in your script: Math.min(limit, maxValue)
- If a larger cap is genuinely needed, fetch multiple pages/batches instead of raising one request's limit
Example fix
// before await runCli(['wikidata', 'search', 'cat', '--limit', '500']); // after const limit = Math.min(500, 50); await runCli(['wikidata', 'search', 'cat', '--limit', String(limit)]);
Defensive patterns
Strategy: validation
Validate before calling
const MAX_LIMIT = 50; // check command docs for the real cap
const n = Number(limit);
if (!Number.isInteger(n) || n <= 0 || n > MAX_LIMIT) throw new Error(`limit must be 1..${MAX_LIMIT}`);
await runCli(['wikidata', 'search', query, '--limit', String(n)]); Type guard
function isBoundedInt(v, max) { return Number.isInteger(v) && v > 0 && v <= max; } Try / catch
try {
await runCli(['wikidata', 'search', query, '--limit', limit]);
} catch (e) {
if (/must be <=/.test(e.message)) {
const cap = Number(e.message.match(/<= (\d+)/)?.[1] ?? 50);
await runCli(['wikidata', 'search', query, '--limit', String(cap)]);
} else throw e;
} Prevention
- Read the command's documented maximum before setting limits
- Clamp values with Math.min(value, max) in callers
- Paginate multiple requests instead of inflating one limit
- Centralize limit constants so caps stay consistent
When it happens
Trigger: Calling requireBoundedInt (via `limit`) with a value above the command's maxValue, e.g. `wikidata search cat --limit 100` when the cap is 50.
Common situations: Assuming the limit is unbounded or has a higher cap than it does; copying a limit from another tool with a bigger maximum; scripts computing limits from result-set sizes.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- --adults must be an integer between 1 and 9, got
- nuget must be a positive integer
- tvmaze must be a positive integer
- wikidata cannot be empty
- wikidata must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3b68beffd87d2a69.
Report an issue: GitHub.
Appendix: source
Thrown at clis/wikidata/utils.js:30
// Q-ID = an item; P-ID = a property; L-ID = a lexeme. We accept all three so the
// adapter can be reused for properties / lexemes without a separate command, but
// search only returns Q-IDs by default.
const ENTITY_ID_PATTERN = /^[QPL]\d+$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`wikidata ${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(`wikidata ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`wikidata ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireEntityId(value) {
const raw = String(value ?? '').trim().toUpperCase();
if (!raw) throw new ArgumentError('wikidata entity id is required (e.g. "Q937")');
// Tolerate URL-paste like `https://www.wikidata.org/wiki/Q937`.
const stripped = raw.replace(/^HTTPS?:\/\/[^/]+\/WIKI\//i, '');
if (!ENTITY_ID_PATTERN.test(stripped)) {
throw new ArgumentError(
`wikidata entity id "${value}" is not a valid Q/P/L identifier`,
'Expected format: "Q<digits>" (item), "P<digits>" (property), or "L<digits>" (lexeme).',
);
}
return stripped;
}
View on GitHub (pinned to 49907e53dc)