jackwener/OpenCLI · error · CommandExecutionError
Zhihu search returned malformed payload
Error message
Zhihu search returned malformed payload
What it means
requireSearchPayload could not normalize the Browser Bridge response into a usable object: unwrapEvaluateResult returned null, a non-object, or an array. The CLI throws CommandExecutionError because the Zhihu search page/bridge returned data in an unexpected shape, so results cannot be parsed.
Source
Thrown at clis/zhihu/search.js:78
}
function requireType(value) {
const type = String(value || 'all');
if (!TYPES.includes(type)) {
throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');
}
return type;
}
function unwrapEvaluateResult(payload) {
if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;
return payload;
}
function requireSearchPayload(data, url) {
const payload = unwrapEvaluateResult(data);
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError('Zhihu search returned malformed payload');
}
if (payload.__httpError) {
const status = payload.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');
}
throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');
}
if (payload.__fetchError) {
throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));
}
if (!Array.isArray(payload.data)) {
throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);
}
if (!payload.paging || typeof payload.paging !== 'object') {
throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);
}
return payload;View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the search — transient page-load issues often resolve on retry
- Verify Chrome and the Browser Bridge extension are running and connected
- Ensure the page is actually www.zhihu.com search results, not a captcha/login interstitial
- Update the CLI/extension if versions mismatched (envelope format change)
- Rerun with -v for verbose output to inspect the raw payload
Example fix
// before: assuming payload always parses
const results = await searchZhihu(q);
// after
try { const results = await searchZhihu(q); }
catch (err) { if (err instanceof CommandExecutionError) { await reconnectBridge(); retry(); } throw err; } Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: confirm the bridge session is alive
const probe = await bridge.evaluate('1 + 1');
if (!probe) throw new Error('Browser Bridge not responding; reconnect Chrome before searching'); Type guard
function isUsablePayload(data) {
const p = data && typeof data === 'object' && 'data' in data && 'session' in data ? data.data : data;
return !!p && typeof p === 'object' && !Array.isArray(p);
} Try / catch
try {
const results = await searchZhihu(q);
} catch (err) {
if (err instanceof CommandExecutionError && err.message === 'Zhihu search returned malformed payload') {
await reconnectBridge();
return searchZhihu(q); // retry once
}
throw err;
} Prevention
- Keep the Browser Bridge extension and CLI versions in sync
- Ensure the Chrome tab is on www.zhihu.com and fully loaded before searching
- Dismiss any captcha/login interstitials before running batch searches
- Run with -v when developing to catch payload-shape changes early
When it happens
Trigger: Running zhihu search when the in-page evaluation returns nothing (page navigated away, script blocked), the Bridge wraps the payload differently than expected ('data'/'session' envelope missing), or the page returned an error string/array instead of an object.
Common situations: Chrome not fully loaded on www.zhihu.com; a Zhihu interstitial/captcha page replacing the normal page; outdated Browser Bridge protocol after an extension update; network drop mid-evaluation.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Zhihu search returned malformed data list
- Zhihu answer detail returned malformed JSON: ${data.__malfor
- Zhihu search returned malformed paging data
- Failed to parse 12306 station_name.js: source string not fou
- Failed to parse 12306 station_name.js: no station records fo
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/dc97c342a9ac73a7.
Report an issue: GitHub.