{"record":{"id":"a31f560d46903164","repo":"jackwener/OpenCLI","slug":"probe-detail-a31f56","errorCode":null,"errorMessage":"${probe.detail}","messagePattern":"\\$\\{probe\\.detail\\}","errorType":"exception","errorClass":"AuthRequiredError('jimeng.jianying.com')","httpStatus":null,"severity":"error","filePath":"clis/jimeng/auth.js","lineNumber":28,"sourceCode":"const WHOAMI_PROBE = `(async () => {\n  try {\n    const r = await fetch('/passport/account/info/v2/?aid=513695', { credentials: 'include', headers: { Accept: 'application/json' } });\n    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Jimeng passport HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    const u = d && d.data;\n    if (!u || !u.user_id || u.is_visitor_account) return { kind: 'auth', detail: 'Jimeng passport returned a visitor account (anonymous)' };\n    return { ok: true, user_id: String(u.user_id_str || u.user_id), screen_name: String(u.screen_name || u.name || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyJimengIdentity(page) {\n  await page.goto('https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('jimeng.jianying.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Jimeng passport`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Jimeng whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Jimeng probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, screen_name: probe.screen_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'jimeng',\n  domain: 'jimeng.jianying.com',\n  loginUrl: 'https://jimeng.jianying.com/',\n  columns: ['user_id', 'screen_name'],\n  verify: verifyJimengIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('jimeng.jianying.com', 'Waiting for Jimeng login');\n    return { user_id: probe.user_id, screen_name: probe.screen_name };\n  },\n});","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jimeng/auth.js#L10-L46","documentation":"verifyJimengIdentity runs a WHOAMI_PROBE script inside the authenticated Jimeng page. When the probe reports kind 'auth', the user is not signed in to jimeng.jianying.com, so an AuthRequiredError is raised with the probe's detail, prompting the interactive login flow.","triggerScenarios":"page.evaluate(WHOAMI_PROBE) executes in the Jimeng page but the embedded whoami API call returns an auth error — i.e. no valid session cookies for jimeng.jianying.com in the attached Chrome profile, or the session expired.","commonSituations":"User never logged into Jimeng in the controlling Chrome instance; cookies cleared or expired; Jimeng invalidated the session server-side; using a fresh Chrome profile without login.","solutions":["Open https://jimeng.jianying.com/ in the attached Chrome window and sign in, then retry","Re-run the site's auth command (registerSiteAuthCommands login flow) to wait for login interactively","Verify cookies for jimeng.jianying.com exist and are not expired","If cookies are valid but the probe still fails, check whether Jimeng changed its whoami endpoint/response shape","Clear stale cookies and log in again if the session is half-broken"],"exampleFix":"// before\nawait verifyJimengIdentity(page); // AuthRequiredError\n// after\ntry {\n  await verifyJimengIdentity(page);\n} catch (err) {\n  if (err instanceof AuthRequiredError) {\n    console.error('Not signed in to Jimeng — run the login flow: open jimeng.jianying.com and sign in.');\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"const probe = await page.evaluate(WHOAMI_PROBE);\nif (probe?.kind === 'auth') throw new AuthRequiredError('jimeng.jianying.com', 'Sign in first');","typeGuard":"function isJimengAuthError(err) {\n  return err instanceof AuthRequiredError && err.message.includes('jimeng');\n}","tryCatchPattern":"try {\n  const identity = await verifyJimengIdentity(page);\n} catch (err) {\n  if (err instanceof AuthRequiredError) {\n    await runJimengLoginFlow(); // interactive sign-in, then retry\n    return verifyJimengIdentity(page);\n  }\n  throw err;\n}","preventionTips":["Always verify Jimeng auth before API-dependent commands","Re-login when cookies are older than the session lifetime","Use a dedicated Chrome profile that stays logged in","Check probe.kind explicitly before consuming probe fields"],"tags":["auth","session-expired","jimeng","browser-automation"],"backgroundTag":"auth-required-login","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}