jackwener/OpenCLI · error · CommandExecutionError
12306 whoami failed: ${probe.detail}
Error message
12306 whoami failed: ${probe.detail} What it means
CommandExecutionError thrown by `twitter bookmark` when the func is invoked with page === null, i.e. no browser session is active. Bookmarking requires driving a real x.com page in a browser, so the command refuses to run headless-less.
Source
Thrown at clis/12306/auth.js:41
return { kind: 'auth', detail: '12306 initMy12306Api redirected to login' };
}
const t = await r.text();
let d = null;
try { d = JSON.parse(t); } catch {}
if (!d || d.status === false || /未登录|登录超时|NotLogin/i.test(t)) {
return { kind: 'auth', detail: '12306 initMy12306Api returned NotLogin' };
}
const userName = d.data?.user_name || d.data?.userName || d.user_name || '';
if (!userName) {
return { kind: 'auth', detail: '12306 initMy12306Api 200 but no user_name surface' };
}
return { ok: true, user_name: String(userName) };
} catch (e) {
return { kind: 'exception', detail: String(e && e.message || e) };
}
})()`);
if (probe?.kind === 'auth') throw new AuthRequiredError('12306.cn', probe.detail);
if (probe?.kind === 'exception') throw new CommandExecutionError(`12306 whoami failed: ${probe.detail}`);
if (!probe?.ok) throw new CommandExecutionError(`Unexpected 12306 probe: ${JSON.stringify(probe)}`);
return { user_name: probe.user_name };
}
registerSiteAuthCommands({
site: '12306',
domain: '12306.cn',
loginUrl: 'https://kyfw.12306.cn/otn/resources/login.html',
columns: ['user_name'],
quickCheck: has12306SessionCookie,
verify: verify12306Identity,
poll: async (page) => {
if (!await has12306SessionCookie(page)) {
throw new AuthRequiredError('12306.cn', 'Waiting for 12306 tk auth cookie');
}
return verify12306Identity(page);
},
});View on GitHub (pinned to 49907e53dc)
Solutions
- Start a browser session first, then run the bookmark command
- Re-open the session if a prior command crashed and closed it
- In scripts, launch the browser before any twitter command and add a readiness check before proceeding
- Check that the session didn't time out between steps — run the commands closer together
Example fix
// before opencli twitter bookmark https://x.com/user/status/123 // after opencli browser open opencli twitter bookmark https://x.com/user/status/123
Defensive patterns
Strategy: validation
Validate before calling
if (!page) throw new Error('Start a browser session before running twitter commands');
// or, for CLI usage: check the session command succeeded first Type guard
function hasSession(page) { return page !== null && page !== undefined; } Try / catch
try {
await opencli('twitter bookmark', url);
} catch (e) {
if (/Browser session required/.test(e.message)) {
await opencli('browser open');
await opencli('twitter bookmark', url); // retry once after starting session
}
} Prevention
- Always launch the browser session before twitter commands in scripts
- Check session liveness between long-running steps
- Wrap multi-step scripts with a session bootstrap and teardown
- Watch for prior command failures that close the session
When it happens
Trigger: Calling the command before starting a browser session; the session was closed/timed out before this call; invoking the CLI from a script or test harness without launching the browser.
Common situations: Scripting the CLI where an earlier command crashed and closed the browser; CI environments with no browser session bootstrap; forgetting the `opencli browser open` (or equivalent) step in a new shell.
Related errors
- Browser session required for twitter delete
- Browser session required for twitter reply
- Browser session required for twitter retweet
- Browser session required for bilibili comment
- Browser session required for bilibili summary
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9f7f4be5be11abc2.
Report an issue: GitHub.