jackwener/OpenCLI · error · CommandExecutionError

Failed to open Zhihu answer ${answerId}: ${err instanceof Er

Error message

Failed to open Zhihu answer ${answerId}: ${err instanceof Error ? err.message : String(err)}

What it means

This CommandExecutionError wraps any failure of page.goto() when navigating to https://www.zhihu.com/answer/<answerId>. Navigation is used both to seed the cookie/anti-bot context and to resolve the canonical question id via Zhihu's redirect, so if the browser cannot load the page the command cannot proceed. The underlying browser error message is embedded in the thrown message.

Source

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

        // full stripped answer". Any positive value is an opt-in user
        // cap, mirroring the wikipedia `page` pattern — we never
        // silently truncate behind the user's back.
        const rawMaxContent = kwargs['max-content'];
        const maxContent = rawMaxContent == null ? 0 : Number(rawMaxContent);
        if (!Number.isInteger(maxContent) || maxContent < 0) {
            throw new ArgumentError(
                '--max-content must be a non-negative integer (0 = no cap, full content)',
                'Example: --max-content 2000',
            );
        }
        // Navigate to the answer page itself: this both seeds the
        // cookie/anti-bot context and works even when the caller did
        // not supply the parent question id (Zhihu redirects from
        // `/answer/<aid>` to the canonical `/question/<qid>/answer/<aid>`).
        try {
            await page.goto(`https://www.zhihu.com/answer/${answerId}`);
        } catch (err) {
            throw new CommandExecutionError(
                `Failed to open Zhihu answer ${answerId}: ${err instanceof Error ? err.message : String(err)}`,
                '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) };
        }
      })()

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify network reachability by opening the answer URL in Chrome manually, then retry the command.
  2. Check DNS/proxy settings (HTTP_PROXY/HTTPS_PROXY or browser proxy) and fix or bypass them.
  3. Retry later if zhihu.com is temporarily unreachable or rate-limiting your IP.
  4. Run with -v to see the underlying browser navigation error details.

Example fix

// before
await page.goto(`https://www.zhihu.com/answer/${answerId}`); // unhandled network failure
// after
try {
  await page.goto(`https://www.zhihu.com/answer/${answerId}`, { timeout: 30000 });
} catch (err) {
  throw new CommandExecutionError(`Failed to open Zhihu answer ${answerId}: ${err.message}`);
}
Defensive patterns

Strategy: retry

Validate before calling

// preflight reachability
const res = await fetch('https://www.zhihu.com/robots.txt').catch(() => null);
if (!res || !res.ok) throw new Error('zhihu.com unreachable — check network/proxy before running');

Type guard

function isNavigationError(err) { return err instanceof Error && /net::|Navigation|timeout/i.test(err.message); }

Try / catch

try {
  await answerDetail(answerId);
} catch (err) {
  if (/Failed to open Zhihu answer/.test(err.message)) {
    await sleep(2000);
    return retry(() => answerDetail(answerId), 3);
  }
  throw err;
}

Prevention

When it happens

Trigger: page.goto('https://www.zhihu.com/answer/<id>') throws: DNS resolution failure, connection timeout/reset, net::ERR_NAME_NOT_RESOLVED, proxy errors, or the browser/page being closed before navigation completes.

Common situations: Offline machine or broken VPN/proxy, corporate firewall blocking zhihu.com, DNS misconfiguration, Zhihu rate-limiting/hard-blocking the client IP at TCP level, or headless browser crashed earlier in the session.

Related errors


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