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

  1. Update the CLI/library to a version compatible with the current Zhihu API shape
  2. Check whether the user profile is restricted/suspended in the browser
  3. Re-authenticate — logged-out responses may omit fields
  4. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3adedf5334153a47. Report an issue: GitHub.