jackwener/OpenCLI · error · CommandExecutionError
Gmail identity probe returned an unexpected result
Error message
Gmail identity probe returned an unexpected result
What it means
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.
Source
Thrown at clis/gmail/auth.js:36
const account = Array.from(document.querySelectorAll('a[aria-label], button[aria-label]'))
.map((node) => String(node.getAttribute('aria-label') || '').trim())
.find((label) => /@/.test(label) && /(google account|google 帐号|google 账号)/i.test(label));
if (!account) {
const login = document.querySelector('a[href*="accounts.google.com/ServiceLogin"], input[type="email"]');
return login
? { kind: 'auth', detail: 'Gmail shows a Google sign-in surface' }
: { kind: 'shape', detail: 'Gmail account control was not found' };
}
const email = account.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i)?.[0] || '';
const beforeEmail = email ? account.slice(0, account.indexOf(email)) : account;
const name = beforeEmail
.replace(/^.*?(?:google account|google 帐号|google 账号)\s*[::]?\s*/i, '')
.replace(/[,((]\s*$/, '')
.trim();
return email ? { ok: true, email, name } : { kind: 'shape', detail: 'Gmail account control did not expose an email address' };
})()`), 'identity probe');
if (result?.kind === 'auth') throw new AuthRequiredError(GMAIL_HOST, result.detail);
if (!result?.ok) throw new CommandExecutionError(result?.detail || 'Gmail identity probe returned an unexpected result');
return { email: result.email, name: result.name || null };
}
registerSiteAuthCommands({
site: 'gmail',
domain: GMAIL_HOST,
loginUrl: 'https://accounts.google.com/ServiceLogin?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F%23inbox',
columns: ['email', 'name'],
quickCheck: hasGoogleSession,
verify: verifyGmailIdentity,
poll: verifyGmailIdentity,
});
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
const identity = await verifyGmailIdentity(page); // throws when DOM differs
// after
try {
const identity = await verifyGmailIdentity(page);
} catch (e) {
if (e instanceof CommandExecutionError) {
await page.sleep(5); // let Gmail finish loading, then retry once
const identity = await verifyGmailIdentity(page);
} else throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const html = await page.content();
if (!/aria-label/.test(html) || /loading|offline/i.test(document?.title ?? '')) {
await page.sleep(5); // Gmail not ready for the identity probe
} Type guard
function isIdentityOk(r) {
return !!r && typeof r === 'object' && r.ok === true && typeof r.email === 'string' && r.email.includes('@');
} Try / catch
try {
identity = await verifyGmailIdentity(page);
} catch (e) {
if (e instanceof CommandExecutionError && /unexpected result/.test(e.message)) {
await page.sleep(5);
identity = await verifyGmailIdentity(page); // one retry after full load
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected Douban probe: ${JSON.stringify(probe)}
- ${result.detail}
- Unexpected NotebookLM probe: ${JSON.stringify(probe)}
- Not a git repository
- Working tree not clean: ${status}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4663a2c1641ab853.
Report an issue: GitHub.