jackwener/OpenCLI · error · CommandExecutionError

Zhihu answer detail payload did not include answer content

Error message

Zhihu answer detail payload did not include answer content

What it means

This CommandExecutionError is thrown when the response object is otherwise valid but lacks a `content` property, verified with Object.prototype.hasOwnProperty.call(data, 'content'). The library requires the answer body field to be present (even if empty); its absence means the payload does not contain the answer content the command exists to extract.

Source

Thrown at clis/zhihu/answer-detail.js:125

            throw new CommandExecutionError(
                `Zhihu answer detail returned malformed JSON: ${data.__malformedJson}`,
                'Try again later or rerun with -v for more detail',
            );
        }
        if (typeof data !== 'object' || Array.isArray(data)) {
            throw new CommandExecutionError(
                'Zhihu answer detail returned a malformed payload',
                'Try again later or rerun with -v for more detail',
            );
        }
        if (data.error || data.error_msg || data.message) {
            throw new CommandExecutionError(
                `Zhihu answer detail returned an error payload: ${data.error?.message || data.error_msg || data.message}`,
                'Try again later or rerun with -v for more detail',
            );
        }
        if (!Object.prototype.hasOwnProperty.call(data, 'content')) {
            throw new CommandExecutionError(
                'Zhihu answer detail payload did not include answer content',
                'Try again later or rerun with -v for more detail',
            );
        }
        const question = data.question || {};
        // Answer ids and newer question ids can exceed
        // Number.MAX_SAFE_INTEGER. Prefer ids parsed from user input or
        // the canonical redirected URL; only fall back to API numeric ids
        // when no string-safe source is available.
        const questionId = target.questionId
            || currentQuestionId
            || extractQuestionIdFromAnswerUrl(question.url)
            || (question.id == null ? '' : String(question.id));
        const stripped = stripHtml(data.content || '');
        // Truncation is opt-in only; default `maxContent === 0` short-
        // circuits the conditional so the full stripped body is returned.
        const content = maxContent > 0 && stripped.length > maxContent
            ? stripped.substring(0, maxContent)

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry later or rerun with -v to inspect the payload and confirm which fields Zhihu returned.
  2. Update the CLI/library if Zhihu changed the payload schema (missing `content` in newer responses).
  3. Try the browser page directly for that answer to see if the content is accessible at all.
  4. Treat restricted/paywalled answers as unsupported and skip them in bulk workflows.
Defensive patterns

Strategy: type-guard

Type guard

function hasContentField(d) { return !!d && typeof d === 'object' && Object.prototype.hasOwnProperty.call(d, 'content'); }

Try / catch

try {
  const detail = await answerDetail(id);
} catch (err) {
  if (/did not include answer content/.test(err.message)) {
    console.warn('Payload missing content — answer may be restricted or schema changed.');
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: The fetched JSON object passes all earlier checks (object, no error fields) but has no own 'content' key — e.g. Zhihu returned a partial/teaser payload or a differently shaped object for this answer.

Common situations: Zhihu A/B API changes omitting `content` for some answers, responses for paywalled/restricted answers lacking the field, or an API version mismatch between the CLI and Zhihu's current payload schema.

Related errors


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