{"record":{"id":"3adedf5334153a47","repo":"jackwener/OpenCLI","slug":"zhihu-user-response-missing-identity-fields","errorCode":null,"errorMessage":"Zhihu user response missing identity fields","messagePattern":"Zhihu user response missing identity fields","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/user.js","lineNumber":45,"sourceCode":"          if (!r.ok) return { __httpError: r.status };\n          return await r.json();\n        } catch (err) {\n          return { __fetchError: err?.message || String(err) };\n        }\n      })()\n    `));\n        if (!data || typeof data !== 'object' || Array.isArray(data) || data.__httpError || data.__fetchError) {\n            const status = data?.__httpError;\n            if (status === 401 || status === 403) {\n                throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu user profile');\n            }\n            if (status === 404) {\n                throw new EmptyResultError('zhihu user', `No Zhihu user was found for ${slug}.`);\n            }\n            throw new CommandExecutionError(status ? `Zhihu user request failed (HTTP ${status})` : 'Zhihu user request failed', data?.__fetchError ? String(data.__fetchError) : 'Try again later or rerun with -v');\n        }\n        if (!data.url_token || !data.id || !data.name) {\n            throw new CommandExecutionError('Zhihu user response missing identity fields', 'Zhihu may have changed its API shape');\n        }\n        return [{\n            url_token: String(data.url_token || ''),\n            name: String(data.name || ''),\n            headline: String(data.headline || ''),\n            followers: data.follower_count ?? 0,\n            following: data.following_count ?? 0,\n            answers: data.answer_count ?? 0,\n            articles: data.articles_count ?? 0,\n            voteup: data.voteup_count ?? 0,\n            url: data.url_token ? `https://www.zhihu.com/people/${data.url_token}` : '',\n        }];\n    },\n});\n","sourceCodeStart":27,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/user.js#L27-L60","documentation":"After a successful fetch, the user command validates that the profile payload contains url_token, id, and name. If any is missing it throws CommandExecutionError 'Zhihu user response missing identity fields' with the hint that Zhihu may have changed its API shape.","triggerScenarios":"Zhihu returning a 2xx response whose JSON lacks url_token/id/name — API schema evolution, restricted/limited profiles omitting fields, or anti-bot responses that look like success but carry stub data.","commonSituations":"Zhihu silently changing the v4 members response contract; logged-out sessions receiving a redacted profile; scraping a suspended user whose profile is stripped of identity fields.","solutions":["Update the CLI/library to a version compatible with the current Zhihu API shape","Check whether the user profile is restricted/suspended in the browser","Re-authenticate — logged-out responses may omit fields","Capture the raw response (with -v) and compare against the expected fields"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"function hasIdentity(d) { return d && !Array.isArray(d) && typeof d.url_token === 'string' && d.url_token && d.id && typeof d.name === 'string'; }\n// precheck the parsed profile before using it\nif (!hasIdentity(profile)) throw new Error('Profile payload lacks url_token/id/name');","typeGuard":"const isZhihuProfile = (d) => typeof d === 'object' && d !== null && !Array.isArray(d) && 'url_token' in d && 'id' in d && 'name' in d;","tryCatchPattern":"try {\n  const user = await fetchZhihuUser(slug);\n} catch (e) {\n  if (e.message.includes('missing identity fields')) {\n    reportApiShapeDrift(e); // flag for library update / manual inspection\n    return null;\n  }\n  throw e;\n}","preventionTips":["Keep the CLI updated for Zhihu API contract changes","Inspect raw responses (-v) when identity fields go missing","Re-authenticate — degraded logged-out payloads can omit fields","Guard downstream code with the type guard instead of trusting the shape"],"tags":["schema","zhihu","response-shape"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}