jackwener/OpenCLI · error · CommandExecutionError

Zhihu user answers returned malformed row identity

Error message

Zhihu user answers returned malformed row identity

What it means

When listing a user's answers, the CLI maps each API item to a row and validates the identity fields: the answer id, the containing question id, and the question title must all be present. If a.id, q.id, or q.title is missing, it throws this CommandExecutionError because the row cannot be rendered or linked correctly. It is a guard against incomplete items in Zhihu's member answers API.

Source

Thrown at clis/zhihu/user-answers.js:29

    access: 'read',
    description: '知乎某用户的回答列表',
    domain: 'www.zhihu.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'user', type: 'string', required: true, positional: true, help: 'User url_token or people URL' },
        { name: 'limit', type: 'int', default: 20, help: 'Number of answers to return (max 1000)' },
    ],
    columns: ['rank', 'question', 'votes', 'comments', 'created', 'url'],
    func: async (page, kwargs) => {
        const slug = parseZhihuUser(kwargs.user);
        const limit = validateLimit(kwargs.limit);
        await page.goto('https://www.zhihu.com');
        const first = `https://www.zhihu.com/api/v4/members/${encodeURIComponent(slug)}/answers?limit=20&offset=0&include=${encodeURIComponent(INCLUDE)}`;
        const items = await fetchZhihuList(page, first, limit, 'user answers');
        return items.map((a, i) => {
            const q = a.question || {};
            if (!a.id || !q.id || !q.title) {
                throw new CommandExecutionError('Zhihu user answers returned malformed row identity');
            }
            return {
                rank: i + 1,
                question: String(q.title || ''),
                votes: a.voteup_count ?? a.reaction?.statistics?.like_count ?? 0,
                comments: a.comment_count ?? 0,
                created: a.created_time ?? a.created ?? 0,
                url: q.id && a.id ? `https://www.zhihu.com/question/${q.id}/answer/${a.id}` : '',
            };
        });
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command; transient partial hydration often resolves
  2. Log the raw item to see which of a.id / q.id / q.title is missing
  3. Adjust the INCLUDE parameter to request question title fields explicitly
  4. Skip malformed items instead of throwing if you control the code

Example fix

// before
if (!a.id || !q.id || !q.title) {
    throw new CommandExecutionError('Zhihu user answers returned malformed row identity');
}
// after
if (!a.id || !q.id || !q.title) {
    console.warn('skipping malformed answer item', a.id);
    return null;
}
Defensive patterns

Strategy: validation

Validate before calling

function isCompleteAnswerItem(a) {
  return Boolean(a?.id && a?.question?.id && a?.question?.title);
}
const safeItems = items.filter(isCompleteAnswerItem);
if (safeItems.length !== items.length) console.warn(`${items.length - safeItems.length} malformed items skipped`);

Type guard

function hasAnswerIdentity(a) {
  return typeof a?.id === 'number' && typeof a?.question?.id === 'number' && typeof a?.question?.title === 'string' && a.question.title !== '';
}

Try / catch

try {
  const rows = await zhihuUserAnswers(slug, limit);
} catch (err) {
  if (err.message.includes('malformed row identity')) {
    console.error('An answer item lacked id/question id/title; inspect the raw API payload');
  } else throw err;
}

Prevention

When it happens

Trigger: An item in the /api/v4/members/<slug>/answers response lacks id, its question object is missing/empty (deleted question), or question.title is absent, while fetchZhihuList succeeded.

Common situations: User's answer attached to a deleted or privacy-restricted question, Zhihu API field rename (question.title moved), partially hydrated include-fields causing q.title to be omitted.

Understand the failure class

Related errors


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