jackwener/OpenCLI · error · ArgumentError
gov-policy ${command} --limit must be <= 20
Error message
gov-policy ${command} --limit must be <= 20 What it means
Thrown by parseGovPolicyLimit when the --limit value is a valid positive integer but exceeds the cap of 20. The gov-policy site queries are bounded to keep scraping sessions fast and avoid rate limiting, so the library rejects larger values up front.
Source
Thrown at clis/gov-policy/utils.js:19
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
const EMPTY_RESULT_PATTERNS = [
/没有找到/,
/暂无/,
/无相关/,
/未找到/,
/搜索结果为\s*0/,
/很抱歉/,
];
export function parseGovPolicyLimit(raw, command) {
const value = raw ?? 10;
const limit = Number(value);
if (!Number.isInteger(limit) || limit < 1) {
throw new ArgumentError(`gov-policy ${command} --limit must be a positive integer`);
}
if (limit > 20) {
throw new ArgumentError(`gov-policy ${command} --limit must be <= 20`);
}
return limit;
}
export function classifyExtractorFailure(command, result) {
const sample = String(result?.sample || '').replace(/\s+/g, ' ').trim();
const url = String(result?.url || '').trim();
if (command === 'search' && EMPTY_RESULT_PATTERNS.some((pattern) => pattern.test(sample))) {
throw new EmptyResultError('gov-policy search', sample ? sample.slice(0, 160) : undefined);
}
const context = [url && `url=${url}`, sample && `sample=${sample.slice(0, 160)}`]
.filter(Boolean)
.join('; ');
throw new CommandExecutionError(
`gov-policy ${command} page did not expose readable result rows`,
context || 'The page structure may have changed or the page did not finish rendering.',
);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Lower --limit to a value between 1 and 20
- Run the command multiple times with pagination (if the subcommand supports page/offset) to gather more rows
- Refine the query keywords so fewer, more relevant results are needed
Example fix
// before --limit 100 // after --limit 20
Defensive patterns
Strategy: validation
Validate before calling
function isWithinGovPolicyCap(raw) {
const n = Number(raw ?? 10);
return Number.isInteger(n) && n >= 1 && n <= 20;
}
if (!isWithinGovPolicyCap(opts.limit)) opts.limit = Math.min(20, Math.max(1, Number(opts.limit) || 10)); Type guard
function isBoundedInt(v, max) { return Number.isInteger(v) && v > 0 && v <= max; } Try / catch
try {
await runGovPolicy('search', { limit: requested });
} catch (err) {
if (/--limit must be <= 20/.test(err.message)) {
console.error('gov-policy caps --limit at 20; page through results instead.');
} else throw err;
} Prevention
- Clamp or warn on limit values above 20 before calling
- Document the 20-row cap in wrappers around gov-policy commands
- Use pagination over large limits when more rows are needed
When it happens
Trigger: Calling a gov-policy command with --limit 21 or higher, e.g. --limit 100.
Common situations: Users expecting API-style unlimited paging, copying --limit 50 from another CLI's convention, batch scripts requesting more rows than the extractor supports.
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
- gov-policy ${command} --limit must be a positive integer
- archive search limit must be <= 100
- coingecko derivatives limit must be <= 500
- limit must be an integer between 1 and 15 (dianping single p
- limit must be an integer between 1 and ${max}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cd60de059bbbf155.
Report an issue: GitHub.