jackwener/OpenCLI · error · CommandExecutionError

Zhihu answer detail request failed: ${err instanceof Error ?

Error message

Zhihu answer detail request failed: ${err instanceof Error ? err.message : String(err)}

What it means

This CommandExecutionError wraps any rejection of the in-page fetch script used to request the Zhihu answer detail API. The command evaluates JavaScript inside the page to fetch the answer JSON; if that fetch rejects (network error, page context destroyed, script evaluation failure), it is re-thrown with the original error message appended. The in-page script itself catches JSON parse errors separately, so this error indicates the fetch/evaluation step itself failed, not bad JSON.

Source

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

                'Open the answer URL in Chrome and retry after the page is reachable.',
            );
        }
        const currentQuestionId = page.getCurrentUrl
            ? extractQuestionIdFromAnswerUrl(await page.getCurrentUrl().catch(() => ''))
            : '';
        const apiUrl = `https://www.zhihu.com/api/v4/answers/${answerId}?include=content,voteup_count,comment_count,author,created_time,updated_time,question`;
        const data = await page.evaluate(`
      (async () => {
        const r = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });
        if (!r.ok) return { __httpError: r.status };
        try {
          return await r.json();
        } catch (error) {
          return { __malformedJson: error instanceof Error ? error.message : String(error) };
        }
      })()
    `).catch((err) => {
            throw new CommandExecutionError(
                `Zhihu answer detail request failed: ${err instanceof Error ? err.message : String(err)}`,
                'Try again later or rerun with -v for more detail.',
            );
        });
        if (!data || data.__httpError) {
            const status = data?.__httpError;
            if (status === 401 || status === 403) {
                throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu answer detail');
            }
            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',
            );

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command; transient fetch failures usually succeed on a second attempt.
  2. Run with -v for more detail to identify whether it is a network vs. page-context error.
  3. Re-authenticate with zhihu.com (log in via the browser profile) if the session expired.
  4. Ensure nothing navigates or closes the page concurrently while the command runs.

Example fix

// before
const data = await page.evaluate(fetchScript); // unhandled rejection
// after
const data = await page.evaluate(fetchScript).catch((err) => {
  throw new CommandExecutionError(`Zhihu answer detail request failed: ${err.message}`);
});
Defensive patterns

Strategy: retry

Type guard

function isFetchFailure(err) { return err instanceof Error && /Zhihu answer detail request failed/.test(err.message); }

Try / catch

try {
  const detail = await answerDetail(id);
} catch (err) {
  if (/Zhihu answer detail request failed/.test(err.message)) {
    return retryWithBackoff(() => answerDetail(id), { attempts: 3, baseMs: 1000 });
  }
  throw err;
}

Prevention

When it happens

Trigger: The page.evaluate(...) promise rejects: the in-page fetch() throws (network failure, CORS/credentials issue, aborted request), or the page navigated/closed mid-evaluation destroying the execution context.

Common situations: Zhihu session invalidated between navigation and fetch, flaky connection dropping the XHR, browser tab crashed or navigated away, or Zhihu anti-bot challenge replacing the page during evaluation.

Related errors


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