jackwener/OpenCLI · error · CommandExecutionError
字幕获取结果对象不符合预期格式
Error message
字幕获取结果对象不符合预期格式
What it means
A CommandExecutionError thrown when page.evaluate returns a result that is not an object with success === true. The in-page fetch script is expected to resolve to { success: true, data: [...] }; anything else (null, undefined, non-object, or success flag absent/false) triggers this guard.
Source
Thrown at clis/bilibili/subtitle.js:117
if (Array.isArray(subJson)) return { success: true, data: subJson };
return { error: 'UNKNOWN_JSON', data: subJson };
} catch (e) {
return { error: 'PARSE_FAILED', text: text.substring(0, 100) };
}
})()
`;
let items;
try {
items = await page.evaluate(fetchJs);
}
catch (err) {
throw new CommandExecutionError(`字幕获取失败: ${err?.message || err}`);
}
if (items?.error) {
throw new CommandExecutionError(`字幕获取失败: ${items.error}${items.text ? ' — ' + items.text : ''}`);
}
if (!items || typeof items !== 'object' || items.success !== true) {
throw new CommandExecutionError('字幕获取结果对象不符合预期格式');
}
const finalItems = items.data;
if (!Array.isArray(finalItems)) {
throw new CommandExecutionError('解析到的字幕列表对象不符合数组格式');
}
if (finalItems.length === 0) {
throw new EmptyResultError('bilibili subtitle', '字幕文件中没有字幕片段。');
}
// 5. 数据映射
return finalItems.map((item, idx) => {
const from = Number(item?.from);
const to = Number(item?.to);
if (!item || typeof item !== 'object' || !Number.isFinite(from) || !Number.isFinite(to)) {
throw new CommandExecutionError('字幕片段缺少有效 from/to 时间戳');
}
return {
index: idx + 1,
from: from.toFixed(2) + 's',View on GitHub (pinned to 49907e53dc)
Solutions
- Retry — transient page/serialization issues often resolve on a second run.
- Ensure the browser page stays open (no navigation) while the command runs.
- Update the library in case the injected fetch script needs to match new API behavior.
- If payloads are huge, check Chrome's structured-clone/serialization limits in the automation setup.
Defensive patterns
Strategy: try-catch
Type guard
const isFetchResult = (r) => !!r && typeof r === 'object' && r.success === true && Array.isArray(r.data);
Try / catch
try {
await run('bilibili subtitle', { url });
} catch (e) {
if (/不符合预期格式/.test(e.message)) {
await sleep(3000);
return run('bilibili subtitle', { url }); // page may have navigated; retry
}
throw e;
} Prevention
- Prevent page navigation during command execution.
- Avoid concurrent automation on the same browser tab.
- Retry once on this error — often a transient evaluate/serialization issue.
- Update the library if the injected script needs fixing.
When it happens
Trigger: page.evaluate resolves to null/undefined (page navigated away, serialization failure), or the injected script's shape changed / an unhandled branch returned something unexpected.
Common situations: Browser page navigated or was recycled during evaluate; very large subtitle payloads hitting serialization limits; a CLI/library bug or an outdated injected script after API changes.
Related errors
- 字幕条目缺少 subtitle_url 字段
- 字幕获取失败: ${err?.message || err}
- 解析到的字幕列表对象不符合数组格式
- 字幕片段缺少有效 from/to 时间戳
- Bilibili relation query returned a malformed attribute
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/99cd8a038412ca95.
Report an issue: GitHub.