{"record":{"id":"9f7f4be5be11abc2","repo":"jackwener/OpenCLI","slug":"12306-whoami-failed-probe-detail","errorCode":null,"errorMessage":"12306 whoami failed: ${probe.detail}","messagePattern":"12306 whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/12306/auth.js","lineNumber":41,"sourceCode":"        return { kind: 'auth', detail: '12306 initMy12306Api redirected to login' };\n      }\n      const t = await r.text();\n      let d = null;\n      try { d = JSON.parse(t); } catch {}\n      if (!d || d.status === false || /未登录|登录超时|NotLogin/i.test(t)) {\n        return { kind: 'auth', detail: '12306 initMy12306Api returned NotLogin' };\n      }\n      const userName = d.data?.user_name || d.data?.userName || d.user_name || '';\n      if (!userName) {\n        return { kind: 'auth', detail: '12306 initMy12306Api 200 but no user_name surface' };\n      }\n      return { ok: true, user_name: String(userName) };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('12306.cn', probe.detail);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`12306 whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected 12306 probe: ${JSON.stringify(probe)}`);\n  return { user_name: probe.user_name };\n}\n\nregisterSiteAuthCommands({\n  site: '12306',\n  domain: '12306.cn',\n  loginUrl: 'https://kyfw.12306.cn/otn/resources/login.html',\n  columns: ['user_name'],\n  quickCheck: has12306SessionCookie,\n  verify: verify12306Identity,\n  poll: async (page) => {\n    if (!await has12306SessionCookie(page)) {\n      throw new AuthRequiredError('12306.cn', 'Waiting for 12306 tk auth cookie');\n    }\n    return verify12306Identity(page);\n  },\n});","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/12306/auth.js#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nopencli twitter bookmark https://x.com/user/status/123\n// after\nopencli browser open\nopencli twitter bookmark https://x.com/user/status/123","handlingStrategy":"validation","validationCode":"if (!page) throw new Error('Start a browser session before running twitter commands');\n// or, for CLI usage: check the session command succeeded first","typeGuard":"function hasSession(page) { return page !== null && page !== undefined; }","tryCatchPattern":"try {\n  await opencli('twitter bookmark', url);\n} catch (e) {\n  if (/Browser session required/.test(e.message)) {\n    await opencli('browser open');\n    await opencli('twitter bookmark', url); // retry once after starting session\n  }\n}","preventionTips":["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"],"tags":["browser-session","twitter","cli","prerequisite"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}