jackwener/OpenCLI · error · ArgumentError
facebook search --limit must be an integer between 1 and ${M
Error message
facebook search --limit must be an integer between 1 and ${MAX_LIMIT} What it means
ArgumentError thrown by requireLimit in clis/facebook/search.js when the --limit value is not an integer in the 1–MAX_LIMIT (50) range. The function coerces input with Number() and rejects NaN, non-integers, and out-of-range values before any network call. This is an input validation guard, so the error fires immediately and locally.
Source
Thrown at clis/facebook/search.js:10
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
const FACEBOOK_HOME = 'https://www.facebook.com';
const MAX_LIMIT = 50;
function requireLimit(value) {
const n = Number(value);
if (!Number.isInteger(n) || n < 1 || n > MAX_LIMIT) {
throw new ArgumentError(`facebook search --limit must be an integer between 1 and ${MAX_LIMIT}`);
}
return n;
}
function requireQuery(value) {
const q = String(value ?? '').trim();
if (!q) throw new ArgumentError('facebook search requires a non-empty query');
return q;
}
function unwrapBrowserResult(value) {
if (value && typeof value === 'object' && 'data' in value) return value.data;
return value;
}
// Modern facebook.com /search/top renders results inside [role="feed"] as
// entity/content links (people, pages, groups, posts) — [role="article"] /
// [role="listitem"] no longer wrap them — and FB seeds scrambled hidden-charView on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 50, e.g. --limit 20
- Validate/coerce the value with Number(value) and Number.isInteger before calling
- Clamp computed values: Math.min(50, Math.max(1, Math.round(n)))
Example fix
// before
cli.search({ limit: '100' });
// after
const n = Math.min(50, Math.max(1, Math.round(Number(rawLimit))));
cli.search({ limit: n }); Defensive patterns
Strategy: validation
Validate before calling
function validLimit(v) {
const n = Number(v);
return Number.isInteger(n) && n >= 1 && n <= 50 ? n : null;
}
const limit = validLimit(rawLimit);
if (limit === null) throw new Error('--limit must be an integer between 1 and 50'); Type guard
function isAllowedLimit(v) {
return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 50;
} Try / catch
try {
await cli.search({ query, limit });
} catch (err) {
if (/must be an integer between 1 and/.test(err.message)) {
console.error('Please pass --limit as an integer 1-50');
process.exitCode = 2;
return;
}
throw err;
} Prevention
- Always coerce and validate CLI args before calling search
- Clamp computed limits to [1, 50] with Math.min/Math.max
- Document the 50-result cap in your wrapper scripts
When it happens
Trigger: Calling facebook search with --limit 0, --limit 51, --limit abc, --limit 2.5, or an empty value that Number() coerces to NaN.
Common situations: Passing a string from CLI args without parsing; copy-pasting a limit above the 50 cap; scripting with a computed value that is a float or null; forgetting the flag so undefined becomes NaN.
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
- --limit must be a positive integer, got ${JSON.stringify(kwa
- `endoflife ${label} must be <= ${maxValue}`
- facebook search requires a non-empty query
- ${label} must be a path/URL or a JSON array: ${errorMessage(
- ${name} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/776e3928bbb830f1.
Report an issue: GitHub.