jackwener/OpenCLI · error · ArgumentError
gov-policy ${command} --limit must be a positive integer
Error message
gov-policy ${command} --limit must be a positive integer What it means
Thrown by parseGovPolicyLimit when the --limit option for a gov-policy subcommand is not a positive integer (non-numeric string, float, zero, or negative). The function coerces via Number() and defaults to 10 when the option is omitted, so this error only fires on explicitly invalid input.
Source
Thrown at clis/gov-policy/utils.js:16
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`,View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a whole number >= 1, e.g. --limit 10
- Omit --limit entirely to use the default of 10
- Quote-free simple digits only: no decimals, commas, units, or sign
- Check any wrapper script for unset/empty variables feeding --limit
Example fix
// before --limit "" // after --limit 10 // or omit --limit to default to 10
Defensive patterns
Strategy: validation
Validate before calling
function isValidGovPolicyLimit(raw) {
const n = Number(raw ?? 10);
return Number.isInteger(n) && n >= 1;
}
if (!isValidGovPolicyLimit(opts.limit)) throw new Error('--limit must be a positive integer'); Type guard
function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; } Try / catch
try {
await runGovPolicy('search', { limit: opts.limit });
} catch (err) {
if (/--limit must be a positive integer/.test(err.message)) {
console.error('Usage: --limit <integer>=1, e.g. --limit 10');
} else throw err;
} Prevention
- Validate numeric CLI options before invoking commands
- Use CLI parsers with integer coercion/validation (e.g. yargs .number().min(1))
- Never interpolate raw shell/env strings into --limit without checking
- Omit --limit to accept the default of 10
When it happens
Trigger: Calling a gov-policy command (search/detail) with --limit set to e.g. "abc", "2.5", "0", "-3", or "" (empty string coerces to 0).
Common situations: Typing --limit=5x, pasting values with spaces or units ("10 items"), scripting with an unset variable that interpolates as an empty or garbage string.
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 <= 20
- manifestPath must point to a JSON array exported by grok/exp
- steam app id "${value}" must be a positive integer
- 文字配图: requested style "${styleName}" is not available for th
- INVALID_ARGUMENT
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4e86e2cc561a47ed.
Report an issue: GitHub.