{"record":{"id":"3a36a1746a0ae2e5","repo":"jackwener/OpenCLI","slug":"unexpected-qwen-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected Qwen probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Qwen probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/qwen/auth.js","lineNumber":39,"sourceCode":"      const token = ${JSON.stringify(token)};\n      const res = await fetch('/api/v1/auths/', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (!d || !d.id) {\n        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ returned no user id' };\n      }\n      return { ok: true, user_id: String(d.id), name: String(d.name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('qwen.ai', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/v1/auths/`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Qwen whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Qwen probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'qwen',\n  domain: 'qwen.ai',\n  loginUrl: 'https://chat.qwen.ai/auth?action=login',\n  columns: ['user_id', 'name'],\n  quickCheck: hasQwenSessionCookie,\n  verify: verifyQwenIdentity,\n  poll: async (page) => {\n    if (!await hasQwenSessionCookie(page)) {\n      throw new AuthRequiredError('qwen.ai', 'Waiting for Qwen token cookie');\n    }\n    return verifyQwenIdentity(page);\n  },\n});\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/qwen/auth.js#L21-L57","documentation":"After running the Qwen whoami probe, verifyQwenIdentity expects exactly one of four result shapes: kind='auth', kind='http', kind='exception', or a result with ok=true. Any other shape (e.g. ok=false with no kind, undefined/null result, malformed object) hits this fallback at clis/qwen/auth.js:39 and throws a CommandExecutionError embedding the JSON of the result.","triggerScenarios":"The inline probe returns {ok:false,...} without a kind field, returns undefined/null, or returns an object with unexpected fields; any call path through verifyQwenIdentity where the probe contract is violated.","commonSituations":"Qwen frontend/API changed so the probe's response parsing returns ok:false without classifying the failure; stale cookies causing a silent non-JSON response the probe mishandles; a CLI version mismatch between the probe script and its result parser.","solutions":["Inspect the JSON in the message: if ok=false, treat it as an auth failure and re-login with `qwen auth login`.","Clear Qwen cookies/session state and log in again to remove stale responses.","Upgrade the CLI to a version whose probe matches the current qwen.ai API.","Report/patch the probe so every non-ok result is classified as auth/http/exception."],"exampleFix":"// probe contract fix\nreturn { kind: 'http', httpStatus: res.status }; // instead of bare { ok: false, status }\n// caller\nif (!result?.ok) throw new CommandExecutionError(`Unexpected Qwen probe: ${JSON.stringify(result)}`);","handlingStrategy":"type-guard","validationCode":"// pre-call sanity\nif (result === undefined || result === null) {\n  throw new Error('Qwen probe returned no result');\n}","typeGuard":"function hasKnownShape(r) {\n  return !!r && typeof r === 'object' &&\n    ('kind' in r ? ['auth','http','exception'].includes(r.kind) : r.ok === true);\n}","tryCatchPattern":"try {\n  const identity = await verifyQwenIdentity(page);\n} catch (e) {\n  if (/Unexpected Qwen probe:/i.test(e.message)) {\n    const payload = JSON.parse(e.message.replace(/^Unexpected Qwen probe: /, ''));\n    if (payload && payload.ok === false) return relogin(); // treat as stale auth\n  }\n  throw e;\n}","preventionTips":["Re-login whenever the embedded JSON shows ok:false — it usually means stale session state.","Keep the CLI updated; probe result contracts break when qwen.ai changes its API.","Wrap probe calls so unclassified results are logged for debugging before rethrow.","Avoid manually editing probe scripts; use the maintained version."],"tags":["auth","contract-violation","qwen","browser-automation"],"backgroundTag":"unexpected-probe-result-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}