{"record":{"id":"17b5d67803f49548","repo":"jackwener/OpenCLI","slug":"failed-to-extract-aibase-daily-news-geterrormes","errorCode":null,"errorMessage":"Failed to extract AIbase daily news: ${getErrorMessage(error)}","messagePattern":"Failed to extract AIbase daily news: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/aibase/news.js","lineNumber":86,"sourceCode":"    }\n    const rows = (Array.isArray(payload.rows) ? payload.rows : [])\n        .map((row, index) => ({\n            rank: index + 1,\n            title: normalizeText(row.title),\n            url: normalizeText(row.url),\n        }))\n        .filter((row) => row.title && row.url);\n    if (rows.length === 0) {\n        throw new EmptyResultError('aibase news', 'AIbase daily page loaded, but no article rows with title and URL were extracted.');\n    }\n    return rows.slice(0, limit).map((row, index) => ({ ...row, rank: index + 1 }));\n}\n\nasync function loadAibaseNews(page, args) {\n    const limit = normalizeLimit(args.limit);\n    await page.goto(AIBASE_DAILY_URL, { waitUntil: 'load', settleMs: 3000 });\n    const payload = await page.evaluate(buildExtractAibaseNewsJs()).catch((error) => {\n        throw new CommandExecutionError(`Failed to extract AIbase daily news: ${getErrorMessage(error)}`);\n    });\n    return toRows(payload, limit);\n}\n\nexport const aibaseNewsCommand = cli({\n    site: 'aibase',\n    name: 'news',\n    access: 'read',\n    description: 'AIbase 日报 - 每天三分钟关注AI行业趋势',\n    domain: 'www.aibase.com',\n    strategy: Strategy.PUBLIC,\n    browser: true,\n    args: [\n        { name: 'limit', type: 'int', default: DEFAULT_LIMIT, help: `Number of news items to return (max ${MAX_LIMIT})` },\n    ],\n    columns: ['rank', 'title', 'url'],\n    func: loadAibaseNews,\n});","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/aibase/news.js#L68-L104","documentation":"loadAibaseNews catches any rejection from page.evaluate(buildExtractAibaseNewsJs()) and rethrows it as a CommandExecutionError 'Failed to extract AIbase daily news: <message>'. This wraps in-page script failures (exceptions thrown inside the browser context) or evaluation infrastructure errors, distinct from payload-shape and selector-drift checks done later in toRows.","triggerScenarios":"The extraction IIFE throws in page context (e.g. new URL(...) on a malformed href throws SyntaxError, or document access fails), or page.evaluate itself rejects (execution context destroyed by navigation, browser closed, evaluate timed out).","commonSituations":"Site emits anchors with malformed hrefs (invalid URL syntax) crashing new URL(); SPA navigations destroying the execution context mid-run; headless browser crashed on the heavy page; browser version incompatibilities with the evaluate API.","solutions":["Read the wrapped message after the colon — it names the underlying in-page error.","Re-run the command; execution-context-destroyed errors are usually transient navigation races.","Harden the extraction script: wrap new URL(anchor.getAttribute('href'), location.href) in try/catch and skip bad hrefs.","Increase settle time before evaluate or switch to foreground mode; refresh the browser session if the browser is in a bad state."],"exampleFix":"// before\nconst url = new URL(anchor.getAttribute('href'), location.href).href;\n// after\nlet url = '';\ntry { url = new URL(anchor.getAttribute('href'), location.href).href; } catch { return; }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runCommand(['aibase', 'news']);\n} catch (e) {\n  if (e instanceof CommandExecutionError && e.message.startsWith('Failed to extract AIbase daily news:')) {\n    const cause = e.message.slice('Failed to extract AIbase daily news:'.length).trim();\n    console.error(`In-page extraction failed (${cause}); retrying`);\n  } else throw e;\n}","preventionTips":["Harden injected scripts with try/catch around URL parsing and DOM access","Increase settle time before evaluate on slow pages","Retry on execution-context-destroyed errors caused by SPA navigations","Keep the browser session and browser binary healthy/up to date"],"tags":["browser","browser-scraping","error-wrapping"],"backgroundTag":"page-evaluate-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}