{"record":{"id":"344d65af46fcdd70","repo":"jackwener/OpenCLI","slug":"result-detail-344d65","errorCode":null,"errorMessage":"${result.detail}","messagePattern":"\\$\\{result\\.detail\\}","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/gmail/auth.js","lineNumber":35,"sourceCode":"  const result = unwrapBrowserResult(await page.evaluate(`(() => {\n    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":17,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/auth.js#L17-L49","documentation":"During the Gmail identity probe, the in-page script can return a result tagged kind:'auth' with a detail string; verifyGmailIdentity converts that into AuthRequiredError(GMAIL_HOST, result.detail). The generic template \"${result.detail}\" means the concrete message comes from the page probe — typically that the account control showed a signed-out/login state.","triggerScenarios":"The page.evaluate identity probe returns { kind: 'auth', detail: ... } — e.g. the probe detected a 'Sign in' button or login redirect in the Gmail UI instead of an authenticated account control.","commonSituations":"Google session cookies exist but the Gmail page still rendered signed-out (stale cookies, session revoked server-side); account picker requiring re-auth; Gmail redirected to a login/choose-account URL; cookie present but for a different Google account than expected.","solutions":["Re-authenticate: open Gmail in the browser and complete sign-in / account selection","Clear Google cookies and log in fresh if cookies are stale","Verify page.goto landed on the expected /mail/u/<index>/ origin, not a login redirect","Catch AuthRequiredError and drive the registered gmail login flow before retrying"],"exampleFix":"// before\nconst identity = await verifyGmailIdentity(page);\n// after\ntry {\n  const identity = await verifyGmailIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await loginSite('gmail');\n    const identity = await verifyGmailIdentity(page);\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const url = page.url?.() ?? '';\nif (/accounts\\.google\\.com|\\/login/.test(url)) {\n  throw new Error('Gmail redirected to login — re-authenticate before probing identity');\n}","typeGuard":"function isAuthProbeResult(r) {\n  return !!r && typeof r === 'object' && ('ok' in r || 'kind' in r);\n}","tryCatchPattern":"try {\n  const identity = await verifyGmailIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await driveGmailLoginFlow(page);\n    return verifyGmailIdentity(page);\n  }\n  throw e;\n}","preventionTips":["Verify the current URL is an authenticated Gmail page before probing","Complete any account-picker/2FA prompts before running identity checks","Catch AuthRequiredError distinctly from CommandExecutionError","Refresh stale sessions when cookies exist but Gmail renders signed-out","Log the probe's detail message to distinguish auth vs shape failures"],"tags":["auth","gmail","probe","session"],"backgroundTag":"auth-required-session-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}