{"record":{"id":"cd60de059bbbf155","repo":"jackwener/OpenCLI","slug":"gov-policy-command-limit-must-be-20","errorCode":null,"errorMessage":"gov-policy ${command} --limit must be <= 20","messagePattern":"gov-policy (.+?) --limit must be <= 20","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/gov-policy/utils.js","lineNumber":19,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nconst EMPTY_RESULT_PATTERNS = [\n    /没有找到/,\n    /暂无/,\n    /无相关/,\n    /未找到/,\n    /搜索结果为\\s*0/,\n    /很抱歉/,\n];\n\nexport function parseGovPolicyLimit(raw, command) {\n    const value = raw ?? 10;\n    const limit = Number(value);\n    if (!Number.isInteger(limit) || limit < 1) {\n        throw new ArgumentError(`gov-policy ${command} --limit must be a positive integer`);\n    }\n    if (limit > 20) {\n        throw new ArgumentError(`gov-policy ${command} --limit must be <= 20`);\n    }\n    return limit;\n}\n\nexport function classifyExtractorFailure(command, result) {\n    const sample = String(result?.sample || '').replace(/\\s+/g, ' ').trim();\n    const url = String(result?.url || '').trim();\n    if (command === 'search' && EMPTY_RESULT_PATTERNS.some((pattern) => pattern.test(sample))) {\n        throw new EmptyResultError('gov-policy search', sample ? sample.slice(0, 160) : undefined);\n    }\n    const context = [url && `url=${url}`, sample && `sample=${sample.slice(0, 160)}`]\n        .filter(Boolean)\n        .join('; ');\n    throw new CommandExecutionError(\n        `gov-policy ${command} page did not expose readable result rows`,\n        context || 'The page structure may have changed or the page did not finish rendering.',\n    );\n}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gov-policy/utils.js#L1-L37","documentation":"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.","triggerScenarios":"Calling a gov-policy command with --limit 21 or higher, e.g. --limit 100.","commonSituations":"Users expecting API-style unlimited paging, copying --limit 50 from another CLI's convention, batch scripts requesting more rows than the extractor supports.","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"],"exampleFix":"// before\n--limit 100\n// after\n--limit 20","handlingStrategy":"validation","validationCode":"function isWithinGovPolicyCap(raw) {\n  const n = Number(raw ?? 10);\n  return Number.isInteger(n) && n >= 1 && n <= 20;\n}\nif (!isWithinGovPolicyCap(opts.limit)) opts.limit = Math.min(20, Math.max(1, Number(opts.limit) || 10));","typeGuard":"function isBoundedInt(v, max) { return Number.isInteger(v) && v > 0 && v <= max; }","tryCatchPattern":"try {\n  await runGovPolicy('search', { limit: requested });\n} catch (err) {\n  if (/--limit must be <= 20/.test(err.message)) {\n    console.error('gov-policy caps --limit at 20; page through results instead.');\n  } else throw err;\n}","preventionTips":["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"],"tags":["validation","cli-argument","gov-policy","limit"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}