jackwener/OpenCLI · error · CommandExecutionError

Zhihu ${label} request failed: ${error instanceof Error ? er

Error message

Zhihu ${label} request failed: ${error instanceof Error ? error.message : String(error)}

What it means

The in-page Zhihu fetch used to load one page of answer comments rejected or threw, and the .catch wrapper converts any such failure into a CommandExecutionError prefixed with which request type (label) failed and the underlying error message. Detail advice: retry later or rerun with -v.

Source

Thrown at clis/zhihu/answer-comments-helpers.js:53

async function fetchCommentPage(page, url, label, notFoundDetail = '') {
    const evaluated = await page.evaluate(async (requestUrl) => {
        const response = await fetch(requestUrl, { credentials: 'include' });
        let body;
        try {
            body = await response.json();
        } catch (error) {
            return { __httpStatus: response.status, __malformedJson: error instanceof Error ? error.message : String(error) };
        }
        const error = body?.error && typeof body.error === 'object' ? body.error : null;
        const result = {
            __httpStatus: response.status,
            __errorCode: error?.code ?? body?.error_code ?? '',
            __errorMessage: error?.message || body?.error_msg || '',
            __needLogin: error?.need_login === true || body?.need_login === true,
        };
        return !response.ok || result.__errorCode || result.__errorMessage || result.__needLogin ? result : body;
    }, url).catch((error) => {
        throw new CommandExecutionError(
            `Zhihu ${label} request failed: ${error instanceof Error ? error.message : String(error)}`,
            'Try again later or rerun with -v for more detail.',
        );
    });
    const payload = unwrapEvaluateResult(evaluated);
    if (payload?.__malformedJson) {
        throw new CommandExecutionError(`Zhihu ${label} returned malformed JSON: ${payload.__malformedJson}`);
    }
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        throw new CommandExecutionError(`Zhihu ${label} returned a malformed payload`);
    }
    const status = payload.__httpStatus;
    const code = String(payload.__errorCode || '');
    if (status >= 400 || code || payload.__errorMessage || payload.__needLogin) {
        if (code === '40362') {
            throw new CommandExecutionError(
                `Zhihu risk control blocked ${label} (40362): ${payload.__errorMessage || 'abnormal request'}`,
                'Open the answer in the connected Chrome profile and retry later.',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command; transient network or rate-limit issues often clear on retry
  2. Rerun with -v to get the Detail line and the underlying error message
  3. Slow down / add delay between paginated comment requests to avoid rate limiting
  4. Verify login state if the endpoint requires authentication; re-authenticate the browser profile
  5. Check connectivity/proxy settings if every request fails the same way
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check connectivity/endpoint before paging
const res = await fetch(url, { method: 'HEAD' }).catch(() => null);
if (!res || !res.ok) console.warn('Zhihu endpoint unreachable; expect request failures');

Try / catch

try {
  const comments = await cli.zhihuAnswerComments(answerId);
} catch (e) {
  if (e.name === 'CommandExecutionError' && /Zhihu .* request failed/.test(e.message)) {
    await sleep(3000);
    return retryWithBackoff(() => cli.zhihuAnswerComments(answerId), 3);
  }
  throw e;
}

Prevention

When it happens

Trigger: page.evaluate fetch throws — network outage, Zhihu API returning 4xx/5xx or rate-limiting, anti-bot interstitial blocking the request, CORS/redirect to a login page, or the evaluate itself timing out/crashing inside the browser context.

Common situations: Zhihu rate limits after rapid sequential comment paging; anonymous sessions hitting auth-required endpoints; regional blocks or proxy issues; Zhihu changing API contracts so the response shape errors out.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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