{"record":{"id":"5b94814c9b7536ba","repo":"jackwener/OpenCLI","slug":"parse-error-5b9481","errorCode":"PARSE_ERROR","errorMessage":"Bloomberg Businessweek page returned malformed story data","messagePattern":"Bloomberg Businessweek page returned malformed story data","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/bloomberg/businessweek.js","lineNumber":107,"sourceCode":"      ${normalizeStoryPathSource}\n      ${extractStoriesSource}\n      const el = document.getElementById('__NEXT_DATA__');\n      if (!el) return { ok: false, error: 'NO_NEXT_DATA', title: document.title };\n      let data;\n      try { data = JSON.parse(el.textContent); }\n      catch (err) { return { ok: false, error: 'BAD_NEXT_DATA', message: String(err) }; }\n      const stories = extractBusinessweekStoriesFromNextData(data);\n      if (!stories) return { ok: false, error: 'NO_MODULES' };\n      return { ok: true, stories };\n    })()`);\n        let result = await loadStories();\n        // Next.js sometimes hydrates slowly — retry once before giving up.\n        if (result && result.ok === false && (result.error === 'NO_NEXT_DATA' || result.error === 'NO_MODULES')) {\n            await page.wait(4);\n            result = await loadStories();\n        }\n        if (!result || typeof result !== 'object') {\n            throw new CliError('PARSE_ERROR', 'Bloomberg Businessweek page returned malformed story data', 'Bloomberg may have changed the page structure.');\n        }\n        if (result.ok === false) {\n            throw new CliError('PARSE_ERROR', `Bloomberg Businessweek page did not expose story data (${result.error})`, 'Bloomberg may have changed the page structure.');\n        }\n        const stories = Array.isArray(result.stories) ? result.stories : [];\n        if (!stories.length) {\n            throw new CliError('NOT_FOUND', 'No Bloomberg Businessweek stories found', 'Bloomberg may have changed the page structure.');\n        }\n        return stories.slice(0, count);\n    },\n});\n\nexport const __test__ = {\n    command,\n    parseBusinessweekLimit,\n    normalizeBusinessweekStoryPath,\n    extractBusinessweekStoriesFromNextData,\n};","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bloomberg/businessweek.js#L89-L125","documentation":"The businessweek command scrapes Bloomberg's Businessweek page expecting Next.js __NEXT_DATA__/module data exposing story entries. This CliError with code PARSE_ERROR fires when the loaded result is not an object — i.e. the page loader returned nothing usable even after the NO_NEXT_DATA/NO_MODULES retry. It indicates the page structure or delivery changed rather than a user mistake.","triggerScenarios":"loadStories() returns null/non-object after the initial attempt and one retry (page.wait(4) then reload) — e.g. the page served a consent/paywall wall, a bot-detection page, or the Next.js data hooks were renamed/removed by a Bloomberg site update.","commonSituations":"Bloomberg redesigns its Next.js frontend; a consent-cookie or paywall interstitial replaces the article list; bot detection blocks the headless browser; geo-blocking changes the served page.","solutions":["Retry later; slow hydration or transient interstitials often resolve","Clear/retry with a real browser profile and accept Bloomberg's consent banner so the real page loads","Inspect the served HTML to find where story data now lives and update loadStories() selectors in clis/bloomberg/businessweek.js","Check for a CLI update — scrape-target changes are usually fixed upstream","Use an alternate source (e.g. Bloomberg RSS) if scraping remains blocked"],"exampleFix":"// before\nconst stories = await getBusinessweekStories(page);\n// after\ntry { const stories = await getBusinessweekStories(page); }\ncatch (e) {\n  if (e.code === 'PARSE_ERROR') console.error('Businessweek page layout changed or blocked; try again later or update the CLI');\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"function isLoadResult(r) {\n  return !!r && typeof r === 'object' && !Array.isArray(r);\n}","tryCatchPattern":"try { const stories = await getBusinessweekStories(page); }\ncatch (e) {\n  if (e instanceof CliError && e.code === 'PARSE_ERROR') { console.error('Page layout changed or blocked; retry later or update selectors'); }\n  else throw e;\n}","preventionTips":["Build in retries with waits for slow Next.js hydration","Keep a real-browser profile and accept consent banners","Alert on PARSE_ERROR to detect upstream page changes fast","Maintain a fallback data source (e.g. RSS) for critical flows"],"tags":["scraping","parse-error","nextjs","bloomberg"],"backgroundTag":"page-structure-changed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}