jackwener/OpenCLI · error · CommandExecutionError

Zhihu answer detail returned a malformed payload

Error message

Zhihu answer detail returned a malformed payload

What it means

This CommandExecutionError is thrown when the parsed response is valid JSON but is not a plain object — typeof data !== 'object' or Array.isArray(data). The library expects the Zhihu answer detail endpoint to return a JSON object; a scalar (string/number), null, or array indicates the response shape is not what the API contract promises.

Source

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

            }
            if (status === 404) {
                throw new EmptyResultError('zhihu answer-detail', `No Zhihu answer was found for ${answerId}.`);
            }
            throw new CommandExecutionError(
                status
                    ? `Zhihu answer detail request failed (HTTP ${status})`
                    : 'Zhihu answer detail request failed',
                'Try again later or rerun with -v for more detail',
            );
        }
        if (data.__malformedJson) {
            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

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry later; if Zhihu changed its API shape, update the CLI/library to a version matching the new contract.
  2. Rerun with -v to capture the raw payload and confirm the unexpected shape.
  3. Check for library/Zhihu API version drift and pin or upgrade accordingly.
Defensive patterns

Strategy: type-guard

Type guard

function isPlainObject(v) { return typeof v === 'object' && v !== null && !Array.isArray(v); }

Try / catch

try {
  const detail = await answerDetail(id);
} catch (err) {
  if (/malformed payload/.test(err.message)) {
    console.error('Zhihu response shape changed — check for CLI/library updates.');
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: The endpoint returns valid JSON whose top-level value is null, an array, a string, or a number instead of an object (e.g. an array wrapper from an unexpected API version or a bare error string).

Common situations: Zhihu changed or versioned the API response shape, a proxy returned its own JSON error body (array of errors), or hitting a different endpoint that returns a list.

Understand the failure class

Related errors


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