{"record":{"id":"38791c349b89b704","repo":"jackwener/OpenCLI","slug":"label-returned-malformed-extraction-payload-38791c","errorCode":null,"errorMessage":"${label} returned malformed extraction payload","messagePattern":"(.+?) returned malformed extraction payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/utils.js","lineNumber":24,"sourceCode":" * `page.evaluate` may return either the raw IIFE value or a\n * `{ session, data }` envelope depending on the browser-bridge version.\n * Adapter code that inspected the payload directly (e.g. `Array.isArray`,\n * truthiness checks on uid strings) silently received the envelope wrapper\n * instead of the inner value. This helper normalizes both shapes so callers\n * can keep their existing checks unchanged.\n */\nexport function unwrapEvaluateResult(payload) {\n    if (payload && !Array.isArray(payload) && typeof payload === 'object' && 'session' in payload && 'data' in payload) {\n        return payload.data;\n    }\n    return payload;\n}\nexport function requireArrayEvaluateResult(payload, label) {\n    if (!Array.isArray(payload)) {\n        if (payload && typeof payload === 'object' && 'error' in payload) {\n            throw new CommandExecutionError(`${label}: ${String(payload.error)}`);\n        }\n        throw new CommandExecutionError(`${label} returned malformed extraction payload`);\n    }\n    return payload;\n}\nexport function requireObjectEvaluateResult(payload, label) {\n    if (!payload || Array.isArray(payload) || typeof payload !== 'object') {\n        throw new CommandExecutionError(`${label} returned malformed extraction payload`);\n    }\n    return payload;\n}\n/** Get the currently logged-in user's uid from Vue store or config API. */\nexport async function getSelfUid(page) {\n    const uid = unwrapEvaluateResult(await page.evaluate(`\n    (() => {\n      const app = document.querySelector('#app')?.__vue_app__;\n      const store = app?.config?.globalProperties?.$store;\n      const uid = store?.state?.config?.config?.uid;\n      if (uid) return String(uid);\n      return null;","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/utils.js#L6-L42","documentation":"requireArrayEvaluateResult expects the evaluate payload to be an array. When the payload is neither an array nor an {error} object, it throws 'malformed extraction payload' prefixed with the extractor label, indicating the injected script returned an unexpected shape (null, string, number, or non-error object).","triggerScenarios":"An injected extraction script returns null/undefined (selector not found and no error path taken), a scalar, or an unexpected object instead of an array; called via weibo data/rawData helpers.","commonSituations":"Weibo changed its DOM so the script's fallback return path is hit; the page is a redirect/login page; browser evaluate context was destroyed before the script finished.","solutions":["Check which extractor (label in the message) returned the bad shape and log the raw payload during debugging.","Verify you are logged in and landed on the expected page type before running extraction.","Update the CLI to match current weibo.com markup.","Harden the injected script to always return an array (possibly empty)."],"exampleFix":"// before\nconst list = document.querySelectorAll('.item');\nreturn { found: list.length };\n// after\nreturn Array.from(document.querySelectorAll('.item')).map(el => ({ text: el.textContent }));","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(payload)) throw new Error(`weibo: unexpected payload ${typeof payload}`);","typeGuard":"function isExtractionArray(p) {\n  return Array.isArray(p) && p.every(x => x && typeof x === 'object');\n}","tryCatchPattern":"try {\n  const items = await rawDataCommand(label);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /malformed/.test(err.message)) {\n    // snapshot page / re-login / update selectors\n  } else throw err;\n}","preventionTips":["Make injected scripts always return arrays (possibly empty)","Wait for page render before evaluating","Guard against redirect/login pages before extraction","Add debug logging of payload types"],"tags":["weibo","validation","payload-shape","type-mismatch"],"backgroundTag":"malformed-extraction-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}