{"record":{"id":"4c1bf9f5114dbcad","repo":"jackwener/OpenCLI","slug":"reuters-whoami-failed-probe-detail","errorCode":null,"errorMessage":"Reuters whoami failed: ${probe.detail}","messagePattern":"Reuters whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reuters/auth.js","lineNumber":42,"sourceCode":"            const u = JSON.parse(localStorage.getItem(oidcKey) || '{}');\n            cuid = String(u?.profile?.cuid || u?.profile?.sub || '');\n          } catch {}\n        }\n        if (!cuid) {\n          const ajs = localStorage.getItem('ajs_user_id');\n          if (ajs && ajs !== 'null') cuid = ajs;\n        }\n        if (!cuid) {\n          return { kind: 'auth', detail: 'Reuters logged-in but cuid missing — session shape drifted' };\n        }\n        return { ok: true, user_id: cuid, subscribed: Boolean(subState.isSubscribed) };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('reuters.com', probe.detail);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Reuters whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Reuters probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, subscribed: probe.subscribed };\n}\n\nregisterSiteAuthCommands({\n  site: 'reuters',\n  domain: 'reuters.com',\n  loginUrl: 'https://www.reuters.com/account/sign-in/',\n  columns: ['user_id', 'subscribed'],\n  verify: verifyReutersIdentity,\n  // No-navigation poll: check localStorage on the current page so login-flow\n  // polling doesn't bounce the user off the sign-in page every interval.\n  poll: async (page) => {\n    const loggedIn = await page.evaluate(`(() => {\n      try {\n        const raw = localStorage.getItem('rcom-subscription-state');\n        return raw ? JSON.parse(raw).isLoggedIn === true : false;\n      } catch { return false; }","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/auth.js#L24-L60","documentation":"verifyReutersIdentity runs an in-page whoami probe via page.evaluate; if the probe throws (a JS exception inside the page or in the injected script), the result has kind 'exception' and the code wraps it in a CommandExecutionError. The library throws this because it cannot determine the Reuters identity when the probe script fails to execute, distinguishing it from an explicit auth wall.","triggerScenarios":"The injected whoami script (executed via page.evaluate) throws an exception — e.g. localStorage access blocked, JSON parse failure on an unexpected response shape, or a runtime error in the page script — so probe.kind === 'exception' at clis/reuters/auth.js:42.","commonSituations":"Reuters page loaded in a broken/incomplete state before the script ran; browser context with localStorage disabled or restricted by cookie-consent overlays; a Reuters DOM/API change breaking the whoami script; anti-bot interstitial replacing the page content.","solutions":["Retry the identity verification after re-loading https://www.reuters.com fully (increase wait time after page.goto).","Check the probe.detail in the message — it names the in-page error; fix the underlying cause (e.g. consent-wall, CSP, blocked localStorage).","Ensure the user is logged in first; run the login/wait flow that throws AuthRequiredError before calling verifyReutersIdentity.","If Reuters changed its page, update the whoami script to match the current site."],"exampleFix":"// before\nconst who = await verifyReutersIdentity(page);\n// after\nlet who;\ntry {\n  who = await verifyReutersIdentity(page);\n} catch (e) {\n  await page.goto('https://www.reuters.com');\n  await page.wait(5);\n  who = await verifyReutersIdentity(page);\n}","handlingStrategy":"try-catch","validationCode":"// before calling, ensure the page is on reuters.com and loaded\nif (!page.url().includes('reuters.com')) await page.goto('https://www.reuters.com');\nawait page.wait(3);","typeGuard":"function isProbeResult(p) {\n  return p != null && typeof p === 'object' &&\n    (p.kind === 'auth' || p.kind === 'exception' || p.ok === true);\n}","tryCatchPattern":"try {\n  const who = await verifyReutersIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    // prompt login\n  } else if (/Reuters whoami failed/.test(e.message)) {\n    // in-page exception: reload page and retry once\n    await page.goto('https://www.reuters.com');\n    await page.wait(5);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always load and wait for the reuters.com page to settle before running identity verification.","Handle consent/cookie walls in the browser profile before automation.","Match AuthRequiredError vs CommandExecutionError separately in catch blocks.","Log probe.detail to diagnose in-page script breakage early after site updates."],"tags":["command-execution","page-evaluate","browser-automation","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"}