{"record":{"id":"6e71d4a7fa8830bc","repo":"jackwener/OpenCLI","slug":"unexpected-quark-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Quark probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Quark probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/quark/auth.js","lineNumber":32,"sourceCode":"    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  },\n});\n","sourceCodeStart":14,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/quark/auth.js#L14-L48","documentation":"Fallback branch of verifyQuarkIdentity: if the WHOAMI_PROBE result is neither ok nor one of the recognized kinds (auth/http/render-error/exception), the probe object is serialized into this CommandExecutionError. It guards against unknown or malformed probe responses so failures are never silently swallowed.","triggerScenarios":"page.evaluate(WHOAMI_PROBE) returns null/undefined or an object lacking the expected kind/ok fields during quark identity verification.","commonSituations":"Quark frontend update changing the probe's return shape; evaluate returning undefined due to script error swallowed by the probe; version mismatch between the automation tool and the current pan.quark.cn page.","solutions":["Inspect the JSON in the message to see the unexpected probe shape returned by the page.","Update the automation library so WHOAMI_PROBE matches the current Quark page/API contract.","Add an explicit retry with a longer wait in case the probe ran before the page finished initializing.","Reproduce by evaluating WHOAMI_PROBE manually in the automated browser to see raw output.","Check whether a login redirect landed on an unexpected page so the probe ran in the wrong context."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const probe = await page.evaluate(WHOAMI_PROBE);\nif (!probe || typeof probe !== 'object' || !('ok' in probe) && !('kind' in probe)) {\n  throw new Error('WHOAMI_PROBE returned malformed data — check library version vs Quark UI');\n}","typeGuard":"function isWellFormedProbe(p) {\n  return !!p && typeof p === 'object' &&\n    (p.ok === true || ['auth','http','render-error','exception'].includes(p.kind));\n}","tryCatchPattern":"try {\n  await verifyQuarkIdentity(page);\n} catch (e) {\n  if (/Unexpected Quark probe:/.test(String(e.message))) {\n    // log full message JSON, re-run login flow, and update tooling\n  } else throw e;\n}","preventionTips":["Keep the automation library in sync with Quark's frontend","Always log the serialized probe payload from the error message","Verify the page is on pan.quark.cn (not a redirect) before probing","Add a smoke test that asserts the probe's return shape weekly"],"tags":["quark","probe","unexpected-state","browser-automation"],"backgroundTag":"unexpected-probe-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}