{"record":{"id":"9bf20842368e6853","repo":"jackwener/OpenCLI","slug":"gov-policy-command-extractor-returned-no-result","errorCode":null,"errorMessage":"gov-policy ${command} extractor returned no result rows","messagePattern":"gov-policy (.+?) extractor returned no result rows","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gov-policy/utils.js","lineNumber":41,"sourceCode":"\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;\n}\n\nexport function wrapBrowserError(command, error) {\n    if (error instanceof ArgumentError || error instanceof EmptyResultError || error instanceof CommandExecutionError) {\n        throw error;\n    }\n    throw new CommandExecutionError(`gov-policy ${command} browser extraction failed: ${error?.message ?? error}`);\n}\n","sourceCodeStart":23,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gov-policy/utils.js#L23-L55","documentation":"Thrown by requireRows when an extractor's parsed rows are not a non-empty array — i.e. the page-level extraction produced nothing usable, typically because every result card was missing required fields (e.g. a title) or the container selectors matched nothing. It guards downstream formatting code from iterating undefined/null.","triggerScenarios":"Calling requireRows(command, rows) after an extractor returns [] or a non-array (e.g. null from a failed querySelectorAll mapping): site renamed card classes, or all cards filtered out by the title-field requirement.","commonSituations":"Detail/listing pages whose markup changed so the extractor's selectors return nothing, partially loaded pages where cards render without titles, scraping a page type the extractor was never built for.","solutions":["Re-run the command to rule out incomplete page rendering","Open the failing page URL in a browser and compare its markup to the extractor's expectations","If the site markup changed, report/patch the adapter's selectors","For the user: try a different query/page that still matches the known layout"],"exampleFix":"// before\nconst rows = extractCards(dom); // may be []\nprocess(rows);\n// after\nconst rows = requireRows('detail', extractCards(dom));\nprocess(rows); // throws a descriptive CommandExecutionError instead of crashing later","handlingStrategy":"type-guard","validationCode":"function rowsAreWellFormed(rows) {\n  return Array.isArray(rows) && rows.length > 0 && rows.every(r => r && typeof r.title === 'string' && r.title.trim());\n}\nif (!rowsAreWellFormed(parsed)) throw new Error('Extractor output missing titled rows');","typeGuard":"function isNonEmptyRowArray(rows) { return Array.isArray(rows) && rows.length > 0 && rows.every(r => r != null && typeof r === 'object'); }","tryCatchPattern":"try {\n  const rows = await govPolicyDetail(url);\n} catch (err) {\n  if (/extractor returned no result rows/.test(err.message)) {\n    console.error('Page markup may have changed; verify selectors.');\n  } else throw err;\n}","preventionTips":["Validate extractor output shape (array, non-empty, required fields) before use","Keep DOM selectors for result cards in sync with site changes","Detect and surface partially rendered cards (missing titles) early","Snapshot key pages in tests to catch selector drift"],"tags":["web-scraping","extraction","gov-policy","dom"],"backgroundTag":"page-structure-changed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}