jackwener/OpenCLI · error · CommandExecutionError
Zhihu user response missing identity fields
Error message
Zhihu user response missing identity fields
What it means
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.
Source
Thrown at clis/zhihu/user.js:45
if (!r.ok) return { __httpError: r.status };
return await r.json();
} catch (err) {
return { __fetchError: err?.message || String(err) };
}
})()
`));
if (!data || typeof data !== 'object' || Array.isArray(data) || data.__httpError || data.__fetchError) {
const status = data?.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu user profile');
}
if (status === 404) {
throw new EmptyResultError('zhihu user', `No Zhihu user was found for ${slug}.`);
}
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');
}
if (!data.url_token || !data.id || !data.name) {
throw new CommandExecutionError('Zhihu user response missing identity fields', 'Zhihu may have changed its API shape');
}
return [{
url_token: String(data.url_token || ''),
name: String(data.name || ''),
headline: String(data.headline || ''),
followers: data.follower_count ?? 0,
following: data.following_count ?? 0,
answers: data.answer_count ?? 0,
articles: data.articles_count ?? 0,
voteup: data.voteup_count ?? 0,
url: data.url_token ? `https://www.zhihu.com/people/${data.url_token}` : '',
}];
},
});
View on GitHub (pinned to 49907e53dc)
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
Defensive patterns
Strategy: type-guard
Validate before calling
function hasIdentity(d) { return d && !Array.isArray(d) && typeof d.url_token === 'string' && d.url_token && d.id && typeof d.name === 'string'; }
// precheck the parsed profile before using it
if (!hasIdentity(profile)) throw new Error('Profile payload lacks url_token/id/name'); Type guard
const isZhihuProfile = (d) => typeof d === 'object' && d !== null && !Array.isArray(d) && 'url_token' in d && 'id' in d && 'name' in d;
Try / catch
try {
const user = await fetchZhihuUser(slug);
} catch (e) {
if (e.message.includes('missing identity fields')) {
reportApiShapeDrift(e); // flag for library update / manual inspection
return null;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- workspace/create returned no workspace_id: ${JSON.stringify(
- ${label} returned malformed data
- semanticscholar citations returned an unexpected payload sha
- semanticscholar paper returned an unexpected payload shape
- semanticscholar recommendations returned an unexpected paylo
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3adedf5334153a47.
Report an issue: GitHub.