{"record":{"id":"4663a2c1641ab853","repo":"jackwener/OpenCLI","slug":"gmail-identity-probe-returned-an-unexpected-result","errorCode":null,"errorMessage":"Gmail identity probe returned an unexpected result","messagePattern":"Gmail identity probe returned an unexpected result","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gmail/auth.js","lineNumber":36,"sourceCode":"    const account = Array.from(document.querySelectorAll('a[aria-label], button[aria-label]'))\n      .map((node) => String(node.getAttribute('aria-label') || '').trim())\n      .find((label) => /@/.test(label) && /(google account|google 帐号|google 账号)/i.test(label));\n    if (!account) {\n      const login = document.querySelector('a[href*=\"accounts.google.com/ServiceLogin\"], input[type=\"email\"]');\n      return login\n        ? { kind: 'auth', detail: 'Gmail shows a Google sign-in surface' }\n        : { kind: 'shape', detail: 'Gmail account control was not found' };\n    }\n    const email = account.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}/i)?.[0] || '';\n    const beforeEmail = email ? account.slice(0, account.indexOf(email)) : account;\n    const name = beforeEmail\n      .replace(/^.*?(?:google account|google 帐号|google 账号)\\s*[:：]?\\s*/i, '')\n      .replace(/[,(（]\\s*$/, '')\n      .trim();\n    return email ? { ok: true, email, name } : { kind: 'shape', detail: 'Gmail account control did not expose an email address' };\n  })()`), 'identity probe');\n  if (result?.kind === 'auth') throw new AuthRequiredError(GMAIL_HOST, result.detail);\n  if (!result?.ok) throw new CommandExecutionError(result?.detail || 'Gmail identity probe returned an unexpected result');\n  return { email: result.email, name: result.name || null };\n}\n\nregisterSiteAuthCommands({\n  site: 'gmail',\n  domain: GMAIL_HOST,\n  loginUrl: 'https://accounts.google.com/ServiceLogin?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F%23inbox',\n  columns: ['email', 'name'],\n  quickCheck: hasGoogleSession,\n  verify: verifyGmailIdentity,\n  poll: verifyGmailIdentity,\n});\n","sourceCodeStart":18,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/auth.js#L18-L49","documentation":"After the Gmail identity probe, any result that is neither kind:'auth' nor ok:true triggers CommandExecutionError with result?.detail or the fallback 'Gmail identity probe returned an unexpected result'. It means the probe ran but its output shape/value was not the expected { ok, email, name } — usually the Gmail DOM did not match what the probe script expects.","triggerScenarios":"unwrapBrowserResult of the page.evaluate probe returns undefined/null, a malformed object, or { kind:'shape', detail:'Gmail account control did not expose an email address' }, so `if (!result?.ok)` throws.","commonSituations":"Gmail UI redesign changed aria-label structure of the account control so no email is extractable; locale variants where the 'Google Account' label text differs; probe executed on a non-inbox page (loading screen, offline banner); browser returned an evaluation error unwrapped into an unexpected shape.","solutions":["Check result.detail in the thrown error (if not the fallback) for the probe's own diagnosis — often 'did not expose an email address'","Open Gmail in the browser and confirm the account avatar/control renders and shows the email","Wait for Gmail to fully load (the flow sleeps 2s; slow loads may need more) and retry","Update the probe selectors/regex to match current Gmail markup and locales if the UI changed","Log the raw probe result on failure to distinguish null vs shape mismatch"],"exampleFix":"// before\nconst identity = await verifyGmailIdentity(page); // throws when DOM differs\n// after\ntry {\n  const identity = await verifyGmailIdentity(page);\n} catch (e) {\n  if (e instanceof CommandExecutionError) {\n    await page.sleep(5); // let Gmail finish loading, then retry once\n    const identity = await verifyGmailIdentity(page);\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const html = await page.content();\nif (!/aria-label/.test(html) || /loading|offline/i.test(document?.title ?? '')) {\n  await page.sleep(5); // Gmail not ready for the identity probe\n}","typeGuard":"function isIdentityOk(r) {\n  return !!r && typeof r === 'object' && r.ok === true && typeof r.email === 'string' && r.email.includes('@');\n}","tryCatchPattern":"try {\n  identity = await verifyGmailIdentity(page);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /unexpected result/.test(e.message)) {\n    await page.sleep(5);\n    identity = await verifyGmailIdentity(page); // one retry after full load\n  } else throw e;\n}","preventionTips":["Wait for Gmail to fully render before probing (loading skeletons break the DOM probe)","Test the probe after Gmail UI updates — aria-label structure changes break it","Account for locale variants of the 'Google Account' label","Log the raw probe result when ok is falsy to diagnose shape issues","Retry once after a short sleep before failing hard"],"tags":["gmail","dom-parsing","probe","gmail-ui"],"backgroundTag":"dom-scrape-selectors-stale","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}