{"record":{"id":"a40a63c8fee1162c","repo":"jackwener/OpenCLI","slug":"reuters-search-failed-inside-the-page-result-er","errorCode":null,"errorMessage":"Reuters search failed inside the page: ${result.error}","messagePattern":"Reuters search failed inside the page: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reuters/search.js","lineNumber":33,"sourceCode":"    description: 'Reuters 路透社新闻搜索',\n    domain: 'www.reuters.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'query', required: true, positional: true, help: 'Search query' },\n        { name: 'limit', type: 'int', default: 10, help: 'Number of results (1-40)' },\n    ],\n    columns: ['rank', 'title', 'date', 'section', 'section_path', 'authors', 'url'],\n    func: async (page, kwargs) => {\n        const limit = parseLimit(kwargs.limit);\n        const query = String(kwargs.query || '').trim();\n        if (!query) {\n            throw new ArgumentError('Search query cannot be empty', 'Provide a non-empty keyword');\n        }\n        await page.goto('https://www.reuters.com');\n        await page.wait(2);\n        const result = await page.evaluate(buildSearchScript(query, limit));\n        if (result?.error) {\n            throw new CommandExecutionError(`Reuters search failed inside the page: ${result.error}`);\n        }\n        if (!result || typeof result !== 'object') {\n            throw new CommandExecutionError('Reuters search API returned an unreadable response');\n        }\n        if (isAuthStatus(result.status) || looksAuthWallText(result.textPreview)) {\n            throw new AuthRequiredError(\n                'www.reuters.com',\n                `Reuters search requires an accessible Reuters browser session or completed human verification${result.status ? ` (HTTP ${result.status})` : ''}`,\n            );\n        }\n        if (result.ok !== true) {\n            const status = Number.isFinite(result.status) && result.status > 0\n                ? `HTTP ${result.status}${result.statusText ? ` ${result.statusText}` : ''}`\n                : 'no upstream response';\n            throw new CommandExecutionError(`Reuters search API failed (${status})`);\n        }\n        if (!result.body) {\n            const detail = result.parseError ? `: ${result.parseError}` : '';","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/search.js#L15-L51","documentation":"A CommandExecutionError raised when the injected Reuters search script reports an error via result.error. The in-page script (built by buildSearchScript and run through page.evaluate) caught a failure — such as the search API being unreachable from the page, a DOM selector mismatch, or a blocked request — and the library surfaces it as a command execution failure.","triggerScenarios":"The search command ran with a valid query, but page.evaluate returned an object with a truthy error field — the in-page search script failed (network error from the page, unexpected DOM/API response, script exception caught internally) at clis/reuters/search.js:33.","commonSituations":"Reuters changed its search endpoint or DOM so the in-page script fails; corporate proxy or anti-bot blocking the search API from within the page; rate limiting from rapid successive searches; page not fully loaded before evaluate.","solutions":["Read result.error appended to the message to identify the in-page failure cause.","Retry after a delay (possible rate limit or transient network issue).","Ensure the page fully loads before searching — increase the post-goto wait or retry after an explicit page.goto('https://www.reuters.com').","If Reuters changed its site, update buildSearchScript's selectors/API call to the current implementation."],"exampleFix":"// before\nconst result = await reutersSearch({ query: 'earnings' });\n// after\nlet result;\nfor (let i = 0; i < 3 && !result; i++) {\n  try {\n    result = await reutersSearch({ query: 'earnings' });\n  } catch (e) {\n    if (!/search failed inside the page/.test(e.message) || i === 2) throw e;\n    await sleep(3000);\n  }\n}","handlingStrategy":"retry","validationCode":"// ensure a healthy page context before searching\nawait page.goto('https://www.reuters.com');\nawait page.wait(3);\nconst ready = await page.evaluate(\"typeof document !== 'undefined' && document.readyState === 'complete'\");\nif (!ready) await page.wait(5);","typeGuard":"function isSearchResult(r) {\n  return r != null && typeof r === 'object' && !('error' in r) && Array.isArray(r.rows || r.results);\n}","tryCatchPattern":"async function searchWithRetry(kwargs, attempts = 3) {\n  for (let i = 1; i <= attempts; i++) {\n    try {\n      return await runCommand('reuters', 'search', kwargs);\n    } catch (e) {\n      const inPage = /Reuters search failed inside the page/.test(e.message);\n      if (!inPage || i === attempts) throw e;\n      await new Promise(r => setTimeout(r, 3000 * i));\n    }\n  }\n}","preventionTips":["Throttle Reuters searches to avoid rate limiting from the site.","Wait for full page load before running the search script.","Parse the result.error suffix in the message to distinguish network vs DOM-selector failures.","Re-check buildSearchScript compatibility after Reuters site updates.","Fall back to re-navigating the page between retries."],"tags":["command-execution","in-page-script","network","reuters"],"backgroundTag":"in-page-script-execution-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}