{"record":{"id":"9bb012f649227296","repo":"jackwener/OpenCLI","slug":"quark-cn","errorCode":null,"errorMessage":"quark.cn","messagePattern":"quark\\.cn","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/quark/auth.js","lineNumber":28,"sourceCode":"    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Quark account/info HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    const data = d && d.data;\n    const isEmpty = !data || Array.isArray(data) || Object.keys(data).length === 0;\n    if (isEmpty) return { kind: 'auth', detail: 'Quark account/info returned empty data — anonymous' };\n    const nickname = String(data.nickname || data.nick_name || data.name || '');\n    if (!nickname) return { kind: 'render-error', detail: 'Quark account/info populated but no nickname field — response shape drift' };\n    return { ok: true, nickname };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyQuarkIdentity(page) {\n  await page.goto('https://pan.quark.cn/');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('quark.cn', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Quark account/info`);\n  if (probe?.kind === 'render-error') throw new CommandExecutionError(probe.detail);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Quark whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Quark probe: ${JSON.stringify(probe)}`);\n  return { nickname: probe.nickname };\n}\n\nregisterSiteAuthCommands({\n  site: 'quark',\n  domain: 'quark.cn',\n  loginUrl: 'https://pan.quark.cn/',\n  columns: ['nickname'],\n  verify: verifyQuarkIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('quark.cn', 'Waiting for Quark login');\n    return { nickname: probe.nickname };\n  },","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/quark/auth.js#L10-L46","documentation":"verifyQuarkIdentity navigates to https://pan.quark.cn/ and runs WHOAMI_PROBE against Quark's account/info endpoint. When the probe classifies the response as kind='auth' (not logged in / missing auth cookies), it throws AuthRequiredError('quark.cn', detail), telling the caller that Quark requires interactive login before any command can proceed.","triggerScenarios":"Running any quark command when the browser profile has no valid Quark session cookies, the session expired, the account/info endpoint returns an auth-required payload, or the probe detects the login page instead of the logged-in drive UI.","commonSituations":"Using a fresh browser profile with no prior quark.cn login; Quark session cookies expired after inactivity; logging out in the shared browser profile; Quark invalidating sessions after a password change or security check; running in an environment where the login cookie was never captured.","solutions":["Open the browser profile used by the tool, log in to pan.quark.cn manually, then re-run the command.","Run the quark login/auth command for this library to capture fresh credentials.","Clear stale cookies and re-authenticate if the session is half-expired.","Verify pan.quark.cn is reachable and not redirecting to a captcha/security check that breaks the session.","If automation is headless, first perform the login step interactively in the same profile."],"exampleFix":"// before\nopencli quark ls   // -> AuthRequiredError: quark.cn\n// after: authenticate first\nopencli quark login   # complete login in the browser\nopencli quark ls","handlingStrategy":"try-catch","validationCode":"// Check for a live Quark session before running commands\nasync function hasQuarkSession(page) {\n  await page.goto('https://pan.quark.cn/');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE); // or a lightweight cookie check\n  return probe?.ok === true;\n}\nif (!(await hasQuarkSession(page))) {\n  console.error('Quark session missing — run the login step first.');\n}","typeGuard":"function isAuthRequiredError(err) {\n  return err instanceof Error && (err.name === 'AuthRequiredError' || /auth required/i.test(String(err.message)));\n}","tryCatchPattern":"try {\n  await cli.run(['quark', 'ls']);\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await cli.run(['quark', 'login']);   // interactive login in the shared profile\n    await cli.run(['quark', 'ls']);      // retry\n  } else throw e;\n}","preventionTips":["Log in to pan.quark.cn in the browser profile the tool uses before automating","Re-authenticate periodically; Quark sessions expire after inactivity","Never share one profile between interactive logout testing and automation","Probe account/info (or check session cookies) before batch operations"],"tags":["auth","session-expired","cookies","quark"],"backgroundTag":"auth-required-login-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}