jackwener/OpenCLI · error · CommandExecutionError

Bilibili conclusion API returned malformed outline

Error message

Bilibili conclusion API returned malformed outline

What it means

readModelResult expects model_result.outline to be an array of chapter sections (or absent, defaulting to []). If the field is present but is not an array — e.g. an object or a string — this CommandExecutionError is thrown because the outline cannot be iterated to build the summary table rows.

Source

Thrown at clis/bilibili/summary.js:96

    }
    let modelResult = data.model_result;
    if (typeof modelResult === 'string') {
        try {
            modelResult = JSON.parse(modelResult);
        } catch {
            throw new CommandExecutionError('Bilibili conclusion API returned malformed model_result JSON');
        }
    }
    if (!modelResult || typeof modelResult !== 'object' || Array.isArray(modelResult)) {
        throw new CommandExecutionError('Bilibili conclusion API returned malformed model_result');
    }
    const summary = String(modelResult.summary ?? '').trim();
    if (!summary) {
        throw new EmptyResultError('bilibili summary', `Bilibili has not generated an AI summary for ${bvid}.`);
    }
    const outline = modelResult.outline ?? [];
    if (!Array.isArray(outline)) {
        throw new CommandExecutionError('Bilibili conclusion API returned malformed outline');
    }
    return { summary, outline };
}

function rowsFromModel(model) {
    const rows = [{ time: '', content: model.summary }];
    for (const section of model.outline) {
        if (!section || typeof section !== 'object' || Array.isArray(section)) {
            throw new CommandExecutionError('Bilibili conclusion API returned malformed outline section');
        }
        const sectionTitle = String(section.title ?? '').trim();
        const sectionTime = formatTime(section.timestamp);
        if (sectionTitle) {
            rows.push({ time: sectionTime, content: `# ${sectionTitle}` });
        }
        const points = section.part_outline ?? [];
        if (!Array.isArray(points)) {
            throw new CommandExecutionError('Bilibili conclusion API returned malformed part outline');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log typeof modelResult.outline and its JSON to see the actual shape.
  2. If outline arrives as an encoded string, JSON.parse it before validation.
  3. Normalize object-shaped outlines via Object.values() before use.
  4. Default to an empty outline (summary-only output) when the shape is unrecognized.
  5. Report/check for recent Bilibili API schema changes.

Example fix

// before
const outline = modelResult.outline ?? [];
if (!Array.isArray(outline)) {
    throw new CommandExecutionError('Bilibili conclusion API returned malformed outline');
}
// after
let outline = modelResult.outline ?? [];
if (typeof outline === 'string') {
    try { outline = JSON.parse(outline); } catch { outline = []; }
}
if (!Array.isArray(outline)) outline = Object.values(outline ?? {});
Defensive patterns

Strategy: validation

Validate before calling

const raw = modelResult?.outline;
const outline = raw == null ? [] : (Array.isArray(raw) ? raw : Object.values(raw));
if (!Array.isArray(outline)) console.warn('outline not usable');

Type guard

function isOutlineArray(v) {
  return v === undefined || v === null || (Array.isArray(v) && v.every(s => s && typeof s === 'object' && !Array.isArray(s)));
}

Try / catch

try {
  const rows = rowsFromModel(model);
} catch (e) {
  if (String(e.message).includes('malformed outline')) {
    return [{ time: '', content: model.summary }];
  }
  throw e;
}

Prevention

When it happens

Trigger: The conclusion API returned a model_result whose outline is a non-array value (object with named keys, JSON-encoded string, etc.), or the caller passed a hand-built model with a wrong outline type.

Common situations: Bilibili changing the outline schema for some videos; middle-layer code that pre-decodes outline into an object; test fixtures with incorrect shapes.

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