{"record":{"id":"17b171dc4067d08d","repo":"jackwener/OpenCLI","slug":"gov-policy-search","errorCode":null,"errorMessage":"gov-policy search","messagePattern":"gov-policy search","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"info","filePath":"clis/gov-policy/utils.js","lineNumber":28,"sourceCode":"];\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}\n\nexport function requireRows(command, rows) {\n    if (!Array.isArray(rows) || rows.length === 0) {\n        throw new CommandExecutionError(\n            `gov-policy ${command} extractor returned no result rows`,\n            'The page structure may have changed or all result cards were missing required title fields.',\n        );\n    }\n    return rows;","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gov-policy/utils.js#L10-L46","documentation":"Thrown by classifyExtractorFailure when command is 'search' and the extracted page sample matches one of the Chinese empty-result patterns (没有找到, 暂无, 未找到, 搜索结果为 0, 很抱歉, etc.). This is the deliberate distinction between 'the search ran fine but found nothing' (EmptyResultError) and a broken page (the fallback CommandExecutionError), so tooling can treat no-hits as a normal outcome.","triggerScenarios":"Running `gov-policy search <keywords>` where the browser-extracted sample text contains a phrase like 没有找到 or 搜索结果为 0 — i.e. the site rendered its zero-results state.","commonSituations":"Searching overly specific or obsolete policy titles, keywords with wrong jurisdiction/date filters, searching terms outside the site's coverage (e.g. local vs national policy).","solutions":["Broaden the search keywords (shorter, more generic terms)","Remove or relax date/category filters and retry","Verify the policy exists by searching the site manually in a browser","Try alternate spellings/synonyms of the policy title"],"exampleFix":"// before\n gov-policy search \"国务院关于印发深化政府采购制度改革方案的通知全文\"\n// after\n gov-policy search \"政府采购制度改革\"","handlingStrategy":"try-catch","validationCode":"const EMPTY_PATTERNS = [/没有找到/, /暂无/, /无相关/, /未找到/, /搜索结果为\\s*0/, /很抱歉/];\n// No reliable pre-call check; instead accept EmptyResultError as a normal no-hits outcome.\nconst likelyNoHits = keywords.length < 2; // over-specific queries commonly return zero results","typeGuard":"function isEmptyResultError(e) { return e instanceof EmptyResultError; }","tryCatchPattern":"try {\n  const results = await govPolicySearch({ q });\n} catch (err) {\n  if (err instanceof EmptyResultError) {\n    console.log('No policies matched; try broader keywords.');\n    return [];\n  }\n  throw err; // real failure\n}","preventionTips":["Treat EmptyResultError as a normal outcome, not a crash","Use short, generic Chinese keywords rather than full policy titles","Relax date/category filters when zero results are expected","Pre-check coverage manually on the gov-policy site for niche topics"],"tags":["empty-result","search","gov-policy","web-scraping"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}