jackwener/OpenCLI · error · CommandExecutionError
Bilibili conclusion API returned malformed model_result
Error message
Bilibili conclusion API returned malformed model_result
What it means
After parsing (or when model_result is already an object), readModelResult validates that model_result is a non-null, non-array object. Bilibili's conclusion API can return model_result as null or an unexpected scalar when no AI summary exists; this CommandExecutionError signals the response shape is not the expected summary structure.
Source
Thrown at clis/bilibili/summary.js:88
}
function readModelResult(data, bvid) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError('Bilibili conclusion API returned malformed data');
}
if (data.code !== 0) {
throw new EmptyResultError('bilibili summary', `Bilibili has not generated an AI summary for ${bvid}.`);
}
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');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Check whether the video actually has an AI summary (try it in the Bilibili web UI) — absence is a valid API outcome, not necessarily a bug.
- Log data.model_result and its typeof before the call to see the real shape.
- Confirm you are passing the conclusion payload's model_result, not the whole response.
- Handle null model_result as an empty-summary case in your own wrapper.
- Update the client if Bilibili changed the response schema.
Example fix
// before
if (!modelResult || typeof modelResult !== 'object' || Array.isArray(modelResult)) {
throw new CommandExecutionError('Bilibili conclusion API returned malformed model_result');
}
// after
if (!modelResult || typeof modelResult !== 'object' || Array.isArray(modelResult)) {
return null; // no AI summary for this video
} Defensive patterns
Strategy: type-guard
Validate before calling
const mr = data?.model_result;
const ok = mr !== null && typeof mr === 'object' && !Array.isArray(mr);
if (!ok) console.warn('no usable model_result for', bvid); Type guard
function isModelResult(v) {
return v !== null && typeof v === 'object' && !Array.isArray(v) && typeof v.summary === 'string';
} Try / catch
try {
const model = await readModelResult(page, bvid);
} catch (e) {
if (String(e.message).endsWith('malformed model_result')) return null;
throw e;
} Prevention
- Pass the conclusion payload's model_result, not the outer response
- Check the video has an AI summary in the web UI first
- Validate payload shape right after fetching
- Watch for Bilibili API schema changes
When it happens
Trigger: model_result is null, a number/boolean, or an array — e.g. the conclusion endpoint returned code 0 but with an empty model_result, or the caller passed the wrong payload object into readModelResult.
Common situations: Videos without an AI conclusion where the API still returns code 0; API contract changes on Bilibili's side; accidentally passing the outer response or view payload instead of the conclusion payload.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Bilibili conclusion API returned malformed data
- Bilibili conclusion API returned malformed model_result JSON
- Bilibili conclusion API returned malformed outline
- Bilibili conclusion API returned malformed part outline
- Bilibili ${label} API returned a malformed payload
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8cab0ea6c3d7420e.
Report an issue: GitHub.