{"record":{"id":"d1119ea0f690b486","repo":"jackwener/OpenCLI","slug":"unexpected-maimai-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Maimai probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Maimai probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"warning","filePath":"clis/maimai/auth.js","lineNumber":36,"sourceCode":"    return {\n      ok: true,\n      user_id: String(user.id),\n      name: String(user.name || ''),\n      company: String(user.company || ''),\n    };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyMaimaiIdentity(page) {\n  await page.goto('https://maimai.cn/');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('maimai.cn', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Maimai`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Maimai whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Maimai probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, name: probe.name, company: probe.company };\n}\n\nregisterSiteAuthCommands({\n  site: 'maimai',\n  domain: 'maimai.cn',\n  loginUrl: 'https://maimai.cn/',\n  columns: ['user_id', 'name', 'company'],\n  verify: verifyMaimaiIdentity,\n  poll: verifyMaimaiIdentity,\n});\n","sourceCodeStart":18,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/maimai/auth.js#L18-L48","documentation":"Fallback error at clis/maimai/auth.js:36: thrown when the probe result is neither auth/http/exception nor a successful ok:true result. The message JSON-stringifies the whole probe for debugging. It guards against unexpected probe shapes — e.g. undefined, null, or an object from a mismatched/older probe implementation.","triggerScenarios":"page.evaluate returns undefined/null (script didn't evaluate, wrong browser context), or returns an object lacking kind and ok — e.g. a probe/evaluate contract mismatch after refactoring, or the evaluate layer serializing the async IIFE incorrectly.","commonSituations":"Running against a modified WHOAMI_PROBE that returns a new shape; evaluate() failing silently and returning undefined; driver/browser version changes altering evaluate return behavior; attaching to the wrong page/frame.","solutions":["Read the JSON in the message to see what the probe actually returned","Confirm the browser context is the maimai.cn tab and evaluate ran (log the raw probe)","Re-run with an unmodified WHOAMI_PROBE to rule out contract drift","Update the CLI/driver if page.evaluate return serialization changed with a browser upgrade"],"exampleFix":"// before\nconst probe = await page.evaluate(WHOAMI_PROBE);\nif (!probe?.ok) throw new CommandExecutionError(`Unexpected Maimai probe: ${JSON.stringify(probe)}`);\n// after\nconst probe = await page.evaluate(WHOAMI_PROBE);\nconsole.debug('probe:', probe);\nif (probe === undefined) throw new Error('page.evaluate returned undefined — check browser context');","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isValidProbe(p) {\n  return p != null && typeof p === 'object' &&\n    (p.ok === true || ['auth', 'http', 'exception'].includes(p.kind));\n}","tryCatchPattern":"try {\n  await verifyMaimaiIdentity(page);\n} catch (e) {\n  if (/Unexpected Maimai probe/.test(e.message)) {\n    console.error(e.message); // includes full probe JSON for diagnosis\n    console.error('Check that the browser context is the maimai.cn tab and the probe script is unmodified');\n  }\n  throw e;\n}","preventionTips":["Log the raw probe result before asserting on it","Never modify WHOAMI_PROBE's return shape without updating all branches","Confirm evaluate targets the maimai.cn page, not another tab/frame","Pin browser/driver versions to avoid evaluate serialization changes"],"tags":["browser-automation","unexpected-state","debugging"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}