{"record":{"id":"a93df649bcfb2b82","repo":"jackwener/OpenCLI","slug":"unexpected-reuters-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Reuters probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Reuters probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reuters/auth.js","lineNumber":43,"sourceCode":"            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; }\n    })()`);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reuters/auth.js#L25-L61","documentation":"After the whoami probe runs, verifyReutersIdentity expects probe to be an object with ok true plus user_id/subscribed. If probe is undefined/null or has ok falsy (but is neither 'auth' nor 'exception'), the library throws this CommandExecutionError because the probe returned an unrecognized/unexpected shape.","triggerScenarios":"page.evaluate returned null/undefined (script was interrupted or returned nothing) or returned an object without ok:true — probe?.ok is falsy at clis/reuters/auth.js:43, so the object is stringified into the message.","commonSituations":"Navigation cancelled mid-evaluate (page redirected); site served a bot-check or consent page so the probe script silently returned undefined; the whoami script's return value changed shape after a Reuters update.","solutions":["Inspect the JSON.stringify(probe) payload in the message to see what the probe actually returned.","Reload the page and retry, ensuring navigation completes before the probe runs.","Log in to reuters.com first so the probe finds a valid session and returns ok:true.","Update the whoami script if Reuters changed the identity endpoint/localStorage keys it reads."],"exampleFix":"// before\nconst who = await verifyReutersIdentity(page);\n// after\nawait page.goto('https://www.reuters.com');\nawait page.wait(3);\nconst who = await verifyReutersIdentity(page);\nif (!who) throw new Error('Reuters identity unavailable; try logging in again');","handlingStrategy":"type-guard","validationCode":"// pre-check that a session exists before verifying identity\nconst state = await page.evaluate(\"localStorage.getItem('rcom-subscription-state')\");\nif (!state) throw new Error('Not logged in to reuters.com; login first');","typeGuard":"function isOkProbe(p) {\n  return p != null && typeof p === 'object' &&\n    p.ok === true && typeof p.user_id !== 'undefined' && typeof p.subscribed === 'boolean';\n}","tryCatchPattern":"try {\n  const who = await verifyReutersIdentity(page);\n} catch (e) {\n  if (/Unexpected Reuters probe/.test(e.message)) {\n    // probe returned null/unexpected shape: reload and retry\n    await page.goto('https://www.reuters.com');\n    await page.wait(5);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Verify a Reuters session exists (localStorage rcom-subscription-state) before calling.","Avoid navigating away from the page while evaluate is in flight.","Handle bot-check/consent interstitials that make evaluate return undefined.","Log the stringified probe from the message when it recurs to detect site shape changes."],"tags":["command-execution","unexpected-response","browser-automation","reuters"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}