jackwener/OpenCLI · error · CommandExecutionError

Read Hupu mentions failed: invalid browser response

Error message

Read Hupu mentions failed: invalid browser response

What it means

The hupu mentions command evaluates an in-page script that fetches the mentions endpoint on my.hupu.com and returns a result object. If the evaluate yields null or a non-object (the script never produced a structured result), the library throws this CommandExecutionError because it cannot even classify success vs auth failure.

Source

Thrown at clis/hupu/mentions.js:131

          return {
            ok: true,
            data: {
              items: items.slice(0, limit),
              hasNextPage,
              pageStr: nextPageStr
            }
          };
        } catch (error) {
          return {
            ok: false,
            error: error instanceof Error ? error.message : String(error)
          };
        }
      })()
    `);
        if (!result || typeof result !== 'object') {
            throw new CommandExecutionError('Read Hupu mentions failed: invalid browser response');
        }
        if (result.status === 401 || result.status === 403) {
            throw new AuthRequiredError('my.hupu.com', 'Read Hupu mentions failed: please log in to Hupu first');
        }
        if (!result.ok) {
            throw new CommandExecutionError(`Read Hupu mentions failed: ${result.error || 'unknown error'}`);
        }
        const items = result.data?.items || [];
        return items.map((item) => {
            const tid = item.tid ? String(item.tid) : '';
            const pid = item.pid ? String(item.pid) : '';
            return {
                time: item.publishTime || '',
                username: item.username || '',
                thread_title: item.threadTitle || '',
                post_content: stripHtml(item.postContent || ''),
                quote_content: stripHtml(item.quoteContent || ''),
                url: tid ? `https://bbs.hupu.com/${tid}.html` : '',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to Hupu first (the sibling AuthRequiredError path only triggers for status 401/403 — a broken page yields this error instead), then retry
  2. Open my.hupu.com/mentions in a browser to confirm the endpoint responds
  3. Retry — transient navigation or network interruptions can yield a null evaluate result
  4. Inspect the injected script in clis/hupu/mentions.js and harden it to always return {status, ok, error} even on internal failure

Example fix

// before
if (!result || typeof result !== 'object') {
  throw new CommandExecutionError('Read Hupu mentions failed: invalid browser response');
}
// after (caller-side handling)
try { const m = await hupuMentions(page); }
catch (e) {
  if (/invalid browser response/.test(e.message)) await reloadAndLogin(page);
  else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

await page.goto('https://my.hupu.com/');
if (!page.url().includes('my.hupu.com')) await hupuLogin(page); // redirected to login

Type guard

function isValidMentionsResult(r) {
  return !!r && typeof r === 'object' && typeof r.status === 'number' && typeof r.ok === 'boolean';
}

Try / catch

try {
  const mentions = await hupuMentions(page);
} catch (e) {
  if (/invalid browser response/.test(e.message)) {
    await ensureHupuLogin(page);        // likely auth/captcha page
    mentions = await hupuMentions(page);
  } else throw e;
}

Prevention

When it happens

Trigger: page.evaluate in the mentions flow returns undefined/null — the injected async IIFE threw in a way that serialized to nothing, the page navigated away mid-evaluate, or the response could not be parsed into the expected {status, ok, data/error} shape.

Common situations: my.hupu.com serving an anti-bot/captcha page so the fetch wrapper is absent; navigation interrupted by a redirect to the login page; Hupu changing the mentions response shape so the script errors before returning; browser context closed.

Related errors


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