{"record":{"id":"f69d63b37a95eb13","repo":"jackwener/OpenCLI","slug":"failed-to-extract-uisdc-news-geterrormessage-er","errorCode":null,"errorMessage":"Failed to extract UISDC news: ${getErrorMessage(error)}","messagePattern":"Failed to extract UISDC news: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/uisdc/news.js","lineNumber":81,"sourceCode":"    const rows = (Array.isArray(payload.rows) ? payload.rows : [])\n        .map((row, index) => ({\n            rank: index + 1,\n            title: normalizeText(row.title),\n            summary: normalizeText(row.summary),\n            url: normalizeText(row.url),\n        }))\n        .filter((row) => row.title && row.url);\n    if (rows.length === 0) {\n        throw new EmptyResultError('uisdc news', 'UISDC news page loaded, but no news 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 loadUisdcNews(page, args) {\n    const limit = normalizeLimit(args.limit);\n    await page.goto(UISDC_NEWS_URL, { waitUntil: 'load', settleMs: 3000 });\n    const payload = await page.evaluate(buildExtractUisdcNewsJs()).catch((error) => {\n        throw new CommandExecutionError(`Failed to extract UISDC news: ${getErrorMessage(error)}`);\n    });\n    return toRows(payload, limit);\n}\n\nexport const uisdcNewsCommand = cli({\n    site: 'uisdc',\n    name: 'news',\n    access: 'read',\n    description: '优设读报 - 最新 AI/设计行业新闻',\n    domain: 'www.uisdc.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', 'summary', 'url'],\n    func: loadUisdcNews,\n});","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/uisdc/news.js#L63-L99","documentation":"If page.evaluate(buildExtractUisdcNewsJs()) rejects (the injected script threw or the evaluation failed), loadUisdcNews wraps it in CommandExecutionError 'Failed to extract UISDC news: <message>'. This is a low-level extraction failure, distinct from payload validation errors.","triggerScenarios":"The injected script throws a TypeError/ReferenceError inside the page context; page navigation context destroyed mid-evaluate (navigation, tab close, crash); browser/CDP communication failure.","commonSituations":"Page navigated or redirected while evaluate was running ('Execution context was destroyed'); extension or anti-bot script throwing and breaking the page context; headless browser crash on heavy pages.","solutions":["Read the wrapped inner message for the underlying cause","Retry — transient navigation races often pass on a second attempt","Increase settleMs or wait for network idle before evaluate to avoid mid-navigation evaluation","Wrap risky parts of buildExtractUisdcNewsJs in try/catch inside the page script and return {ok:false, reason} instead of throwing"],"exampleFix":"// before\nreturn [...document.querySelectorAll('.news-list li')].map(parseRow);\n// after\ntry { return { ok: true, rows: [...document.querySelectorAll('.news-list li')].map(parseRow) }; }\ncatch (e) { return { ok: false, reason: String(e && e.message || e) }; }","handlingStrategy":"retry","validationCode":"await page.goto(UISDC_NEWS_URL, { waitUntil: 'load', settleMs: 3000 });\nif (page.isClosed() || page.url() !== UISDC_NEWS_URL) throw new Error('page not ready for extraction');","typeGuard":"function isExtractionFailure(e) { return e instanceof Error && /Failed to extract UISDC news/.test(e.message); }","tryCatchPattern":"for (let i = 0; i < 3; i++) { try { return await loadUisdcNews(page, args); } catch (e) { if (isExtractionFailure(e) && i < 2) { page = await reopenPage(); continue; } throw e; } }","preventionTips":["Guard the in-page script body with try/catch returning {ok:false, reason} instead of throwing","Wait for network idle / a specific selector before evaluate to avoid context-destroyed races","Avoid navigating or closing the page while evaluate is in flight","Retry transient failures with a fresh page/context"],"tags":["scraping","page-evaluate","execution-context","command-execution-error"],"backgroundTag":"page-evaluate-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}