jackwener/OpenCLI · error · CommandExecutionError

Reuters search failed inside the page: ${result.error}

Error message

Reuters search failed inside the page: ${result.error}

What it means

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.

Source

Thrown at clis/reuters/search.js:33

    description: 'Reuters 路透社新闻搜索',
    domain: 'www.reuters.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'query', required: true, positional: true, help: 'Search query' },
        { name: 'limit', type: 'int', default: 10, help: 'Number of results (1-40)' },
    ],
    columns: ['rank', 'title', 'date', 'section', 'section_path', 'authors', 'url'],
    func: async (page, kwargs) => {
        const limit = parseLimit(kwargs.limit);
        const query = String(kwargs.query || '').trim();
        if (!query) {
            throw new ArgumentError('Search query cannot be empty', 'Provide a non-empty keyword');
        }
        await page.goto('https://www.reuters.com');
        await page.wait(2);
        const result = await page.evaluate(buildSearchScript(query, limit));
        if (result?.error) {
            throw new CommandExecutionError(`Reuters search failed inside the page: ${result.error}`);
        }
        if (!result || typeof result !== 'object') {
            throw new CommandExecutionError('Reuters search API returned an unreadable response');
        }
        if (isAuthStatus(result.status) || looksAuthWallText(result.textPreview)) {
            throw new AuthRequiredError(
                'www.reuters.com',
                `Reuters search requires an accessible Reuters browser session or completed human verification${result.status ? ` (HTTP ${result.status})` : ''}`,
            );
        }
        if (result.ok !== true) {
            const status = Number.isFinite(result.status) && result.status > 0
                ? `HTTP ${result.status}${result.statusText ? ` ${result.statusText}` : ''}`
                : 'no upstream response';
            throw new CommandExecutionError(`Reuters search API failed (${status})`);
        }
        if (!result.body) {
            const detail = result.parseError ? `: ${result.parseError}` : '';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read result.error appended to the message to identify the in-page failure cause.
  2. Retry after a delay (possible rate limit or transient network issue).
  3. Ensure the page fully loads before searching — increase the post-goto wait or retry after an explicit page.goto('https://www.reuters.com').
  4. If Reuters changed its site, update buildSearchScript's selectors/API call to the current implementation.

Example fix

// before
const result = await reutersSearch({ query: 'earnings' });
// after
let result;
for (let i = 0; i < 3 && !result; i++) {
  try {
    result = await reutersSearch({ query: 'earnings' });
  } catch (e) {
    if (!/search failed inside the page/.test(e.message) || i === 2) throw e;
    await sleep(3000);
  }
}
Defensive patterns

Strategy: retry

Validate before calling

// ensure a healthy page context before searching
await page.goto('https://www.reuters.com');
await page.wait(3);
const ready = await page.evaluate("typeof document !== 'undefined' && document.readyState === 'complete'");
if (!ready) await page.wait(5);

Type guard

function isSearchResult(r) {
  return r != null && typeof r === 'object' && !('error' in r) && Array.isArray(r.rows || r.results);
}

Try / catch

async function searchWithRetry(kwargs, attempts = 3) {
  for (let i = 1; i <= attempts; i++) {
    try {
      return await runCommand('reuters', 'search', kwargs);
    } catch (e) {
      const inPage = /Reuters search failed inside the page/.test(e.message);
      if (!inPage || i === attempts) throw e;
      await new Promise(r => setTimeout(r, 3000 * i));
    }
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/a40a63c8fee1162c. Report an issue: GitHub.