jackwener/OpenCLI · error · CommandExecutionError

字幕片段缺少有效 from/to 时间戳

Error message

字幕片段缺少有效 from/to 时间戳

What it means

A CommandExecutionError thrown during the final data mapping when a cue item in the subtitle body lacks finite numeric from/to timestamps. Each cue must have numeric start (from) and end (to) seconds to render the index/from/to/content output; malformed cues abort the whole mapping.

Source

Thrown at clis/bilibili/subtitle.js:131

        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 JSON for the offending cue's actual field names.
  2. Update the library if Bilibili renamed from/to fields.
  3. Filter out malformed cues in a local fork/patch instead of aborting on the first bad one.
  4. Try another subtitle track (--lang) whose file may be well-formed.

Example fix

// before
if (!item || typeof item !== 'object' || !Number.isFinite(from) || !Number.isFinite(to)) {
  throw new CommandExecutionError('字幕片段缺少有效 from/to 时间戳');
}
// after
if (!item || typeof item !== 'object' || !Number.isFinite(from) || !Number.isFinite(to)) {
  console.warn(`跳过无效字幕片段 #${idx + 1}`);
  return null;
}
Defensive patterns

Strategy: validation

Validate before calling

const cuesValid = (items) => Array.isArray(items) && items.every(i => i && Number.isFinite(Number(i.from)) && Number.isFinite(Number(i.to)));

Type guard

const isCue = (i) => !!i && typeof i === 'object' && Number.isFinite(Number(i.from)) && Number.isFinite(Number(i.to));

Try / catch

try {
  await run('bilibili subtitle', { url });
} catch (e) {
  if (/from\/to/.test(e.message)) throw new Error('Subtitle file has malformed cues; inspect raw JSON or try another track.');
  throw e;
}

Prevention

When it happens

Trigger: A cue object in the CDN JSON body has missing, null, NaN, or non-numeric from/to — e.g. schema drift, corrupted cue entries, or items that are not objects (item is null).

Common situations: Bilibili changing cue field names (from/to→start/end); malformed entries in AI-generated subtitle files; hand-edited or third-party uploaded subtitle files with bad timings.

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/aa57555c1ef91c4c. Report an issue: GitHub.