{"record":{"id":"4e86e2cc561a47ed","repo":"jackwener/OpenCLI","slug":"gov-policy-command-limit-must-be-a-positive-i","errorCode":null,"errorMessage":"gov-policy ${command} --limit must be a positive integer","messagePattern":"gov-policy (.+?) --limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/gov-policy/utils.js","lineNumber":16,"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`,","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gov-policy/utils.js#L1-L34","documentation":"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.","triggerScenarios":"Calling a gov-policy command (search/detail) with --limit set to e.g. \"abc\", \"2.5\", \"0\", \"-3\", or \"\" (empty string coerces to 0).","commonSituations":"Typing --limit=5x, pasting values with spaces or units (\"10 items\"), scripting with an unset variable that interpolates as an empty or garbage string.","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"],"exampleFix":"// before\n--limit \"\"\n// after\n--limit 10   // or omit --limit to default to 10","handlingStrategy":"validation","validationCode":"function isValidGovPolicyLimit(raw) {\n  const n = Number(raw ?? 10);\n  return Number.isInteger(n) && n >= 1;\n}\nif (!isValidGovPolicyLimit(opts.limit)) throw new Error('--limit must be a positive integer');","typeGuard":"function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  await runGovPolicy('search', { limit: opts.limit });\n} catch (err) {\n  if (/--limit must be a positive integer/.test(err.message)) {\n    console.error('Usage: --limit <integer>=1, e.g. --limit 10');\n  } else throw err;\n}","preventionTips":["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"],"tags":["validation","cli-argument","gov-policy"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}