{"record":{"id":"6db451184840f449","repo":"jackwener/OpenCLI","slug":"zhihu-user-answers-returned-malformed-row-identity","errorCode":null,"errorMessage":"Zhihu user answers returned malformed row identity","messagePattern":"Zhihu user answers returned malformed row identity","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/user-answers.js","lineNumber":29,"sourceCode":"    access: 'read',\n    description: '知乎某用户的回答列表',\n    domain: 'www.zhihu.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'user', type: 'string', required: true, positional: true, help: 'User url_token or people URL' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of answers to return (max 1000)' },\n    ],\n    columns: ['rank', 'question', 'votes', 'comments', 'created', 'url'],\n    func: async (page, kwargs) => {\n        const slug = parseZhihuUser(kwargs.user);\n        const limit = validateLimit(kwargs.limit);\n        await page.goto('https://www.zhihu.com');\n        const first = `https://www.zhihu.com/api/v4/members/${encodeURIComponent(slug)}/answers?limit=20&offset=0&include=${encodeURIComponent(INCLUDE)}`;\n        const items = await fetchZhihuList(page, first, limit, 'user answers');\n        return items.map((a, i) => {\n            const q = a.question || {};\n            if (!a.id || !q.id || !q.title) {\n                throw new CommandExecutionError('Zhihu user answers returned malformed row identity');\n            }\n            return {\n                rank: i + 1,\n                question: String(q.title || ''),\n                votes: a.voteup_count ?? a.reaction?.statistics?.like_count ?? 0,\n                comments: a.comment_count ?? 0,\n                created: a.created_time ?? a.created ?? 0,\n                url: q.id && a.id ? `https://www.zhihu.com/question/${q.id}/answer/${a.id}` : '',\n            };\n        });\n    },\n});\n","sourceCodeStart":11,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/user-answers.js#L11-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run the command; transient partial hydration often resolves","Log the raw item to see which of a.id / q.id / q.title is missing","Adjust the INCLUDE parameter to request question title fields explicitly","Skip malformed items instead of throwing if you control the code"],"exampleFix":"// before\nif (!a.id || !q.id || !q.title) {\n    throw new CommandExecutionError('Zhihu user answers returned malformed row identity');\n}\n// after\nif (!a.id || !q.id || !q.title) {\n    console.warn('skipping malformed answer item', a.id);\n    return null;\n}","handlingStrategy":"validation","validationCode":"function isCompleteAnswerItem(a) {\n  return Boolean(a?.id && a?.question?.id && a?.question?.title);\n}\nconst safeItems = items.filter(isCompleteAnswerItem);\nif (safeItems.length !== items.length) console.warn(`${items.length - safeItems.length} malformed items skipped`);","typeGuard":"function hasAnswerIdentity(a) {\n  return typeof a?.id === 'number' && typeof a?.question?.id === 'number' && typeof a?.question?.title === 'string' && a.question.title !== '';\n}","tryCatchPattern":"try {\n  const rows = await zhihuUserAnswers(slug, limit);\n} catch (err) {\n  if (err.message.includes('malformed row identity')) {\n    console.error('An answer item lacked id/question id/title; inspect the raw API payload');\n  } else throw err;\n}","preventionTips":["Ensure the INCLUDE query parameter requests question id and title fields","Filter incomplete items (deleted questions) before rendering","Monitor Zhihu API field names for drift","Treat individual bad rows as skippable in aggregation contexts"],"tags":["zhihu","user-answers","data-validation","api"],"backgroundTag":"malformed-api-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}