jackwener/OpenCLI · error · CommandExecutionError

解析到的字幕列表对象不符合数组格式

Error message

解析到的字幕列表对象不符合数组格式

What it means

A CommandExecutionError thrown when items.data (the parsed subtitle body from the CDN) is not an array. Bilibili subtitle JSON files normally contain a body array of cue objects; a non-array means the CDN returned something else (e.g. an error object or changed schema).

Source

Thrown at clis/bilibili/subtitle.js:121

         }
      })()
    `;
        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',
                to: to.toFixed(2) + 's',
                content: String(item.content ?? '')
            };
        });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the fetched subtitle JSON to see its actual structure.
  2. Update the CLI/library if Bilibili changed the subtitle file schema.
  3. Try a non-AI CC subtitle (different --lang) to see if only AI subtitle files differ.
  4. Report the raw JSON payload with a bug report if the schema changed upstream.
Defensive patterns

Strategy: type-guard

Validate before calling

// If you fetch the subtitle JSON yourself first:
const body = json.body ?? json.data;
if (!Array.isArray(body)) throw new Error('subtitle cues not an array');

Type guard

const isCueList = (d) => Array.isArray(d) && d.every(c => c && typeof c === 'object');

Try / catch

try {
  await run('bilibili subtitle', { url });
} catch (e) {
  if (/不符合数组格式/.test(e.message)) throw new Error('Bilibili subtitle JSON schema changed; inspect raw CDN payload.');
  throw e;
}

Prevention

When it happens

Trigger: The CDN subtitle JSON's relevant field is not an array — e.g. Bilibili renamed body→data or wrapped it, or the fetched JSON is actually an error payload that still passed earlier checks.

Common situations: Bilibili API/CDN format migration; fetching a JSON that is an auth/error response; ai-subtitle (智能字幕) files with a different structure than CC files.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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