{"record":{"id":"836047065c42300e","repo":"jackwener/OpenCLI","slug":"label-returned-a-malformed-payload","errorCode":null,"errorMessage":"${label} returned a malformed payload","messagePattern":"(.+?) returned a malformed payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/video.js","lineNumber":7,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { apiGet, resolveBvid, parsePageArg, selectVideoPart } from './utils.js';\n\nfunction requireObject(value, label) {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) {\n    throw new CommandExecutionError(`${label} returned a malformed payload`);\n  }\n  return value;\n}\n\nfunction unwrapBrowserResult(value) {\n  if (value && typeof value === 'object' && typeof value.session === 'string' && Object.hasOwn(value, 'data')) {\n    return value.data;\n  }\n  return value;\n}\n\nfunction readOptionalFlag(value, label) {\n  if (value == null) return false;\n  if (typeof value === 'boolean') return value;\n  if (typeof value === 'number') return value !== 0;\n  throw new CommandExecutionError(`${label} returned a malformed flag`);\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/video.js#L1-L25","documentation":"requireObject in clis/bilibili/video.js validates that an API payload is a non-null, non-array object before field access. This CommandExecutionError fires when the Bilibili view/detail API returns anything else (null, array, primitive), typically inside the d and rights command handlers.","triggerScenarios":"apiGet resolves to null/undefined, an array, or a string — e.g. the browser session returned an HTML page, an anti-bot interstitial, or the API replied with a non-object error body.","commonSituations":"Bilibili serving a risk-control/captcha page; session expired so the fetch returns a login redirect; API schema change wrapping data differently; empty response on transient server errors.","solutions":["Re-run the command with a fresh browser session (the CLI may require re-authentication)","Retry later; risk-control interstitials are often transient","Log the raw payload in the video command to see what Bilibili actually returned","Update requireObject call sites in clis/bilibili/video.js if the API now legitimately wraps results differently"],"exampleFix":"// before\nconst d = requireObject(payload.data, 'Bilibili view API data');\n// after\nif (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n  throw new CommandExecutionError(`Bilibili view API returned unexpected body: ${JSON.stringify(payload).slice(0, 200)}`);\n}\nconst d = requireObject(payload.data, 'Bilibili view API data');","handlingStrategy":"type-guard","validationCode":"// confirm a healthy browser session exists before invoking video commands\nif (!session || !session.page) throw new Error('start a browser session first');","typeGuard":"function isPlainObject(v) {\n  return !!v && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try { await runVideoCommand(args); }\ncatch (e) {\n  if (e instanceof CommandExecutionError && e.message.includes('malformed payload')) { console.error('Non-object API response; retry with fresh session'); }\n  else throw e;\n}","preventionTips":["Refresh browser sessions regularly to avoid login-redirect HTML","Watch for Bilibili risk-control/captcha pages","Log raw payloads when validation fails","Pin and update the CLI as Bilibili evolves its API"],"tags":["api","malformed-response","bilibili","validation"],"backgroundTag":"api-response-schema-changed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}