jackwener/OpenCLI · info · EmptyResultError

字幕文件中没有字幕片段。

Error message

字幕文件中没有字幕片段。

What it means

An EmptyResultError thrown when the CDN subtitle JSON parsed successfully and its cue list is an array, but the array has zero entries. The subtitle file exists and is valid — it just contains no subtitle lines.

Source

Thrown at clis/bilibili/subtitle.js:124

        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. Verify in the web player whether the chosen subtitle track displays any lines.
  2. Pick a different subtitle language/track via --lang if one exists.
  3. Treat as 'no subtitles in this track' in your wrapper and fall back gracefully.
  4. Re-run later if AI subtitles are still being generated.

Example fix

// before
await run('bilibili subtitle', { url });
// after
try {
  await run('bilibili subtitle', { url });
} catch (e) {
  if (e instanceof EmptyResultError) return [];
  throw e;
}
Defensive patterns

Strategy: fallback

Validate before calling

// No pre-call check; optionally verify the track shows lines in the web player first.

Try / catch

try {
  const cues = await run('bilibili subtitle', { url, lang });
} catch (e) {
  if (e.name === 'EmptyResultError') {
    const alt = await run('bilibili subtitle', { url }).catch(() => null); // try default track
    return alt ?? [];
  }
  throw e;
}

Prevention

When it happens

Trigger: The subtitle JSON body array is empty: uploader created an empty CC track, or an AI-subtitle job produced no cues.

Common situations: Empty subtitle track uploaded by mistake; AI subtitle generation completed with no transcribable speech; muted/music-only videos with an auto-generated empty track.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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