jackwener/OpenCLI · info · EmptyResultError
gov-policy search
Error message
gov-policy search
What it means
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.
Source
Thrown at clis/gov-policy/utils.js:28
];
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.',
);
}
export function requireRows(command, rows) {
if (!Array.isArray(rows) || rows.length === 0) {
throw new CommandExecutionError(
`gov-policy ${command} extractor returned no result rows`,
'The page structure may have changed or all result cards were missing required title fields.',
);
}
return rows;View on GitHub (pinned to 49907e53dc)
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
Example fix
// before gov-policy search "国务院关于印发深化政府采购制度改革方案的通知全文" // after gov-policy search "政府采购制度改革"
Defensive patterns
Strategy: try-catch
Validate before calling
const EMPTY_PATTERNS = [/没有找到/, /暂无/, /无相关/, /未找到/, /搜索结果为\s*0/, /很抱歉/]; // No reliable pre-call check; instead accept EmptyResultError as a normal no-hits outcome. const likelyNoHits = keywords.length < 2; // over-specific queries commonly return zero results
Type guard
function isEmptyResultError(e) { return e instanceof EmptyResultError; } Try / catch
try {
const results = await govPolicySearch({ q });
} catch (err) {
if (err instanceof EmptyResultError) {
console.log('No policies matched; try broader keywords.');
return [];
}
throw err; // real failure
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- No 12306 stations match "${keyword}"
- ${label}
- No papers found for author "${authorText}". Try alternate sp
- No papers found. Try a different keyword.
- crates search
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/17b171dc4067d08d.
Report an issue: GitHub.