{"record":{"id":"09ee7a83357d0e7a","repo":"jackwener/OpenCLI","slug":"twitter-article-response-payload-is-malformed","errorCode":null,"errorMessage":"Twitter article response payload is malformed","messagePattern":"Twitter article response payload is malformed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/article.js","lineNumber":246,"sourceCode":"          else if (blockType === 'unordered-list-item') parts.push('- ' + text);\n          else if (blockType === 'ordered-list-item') {\n            orderedCounter++;\n            parts.push(orderedCounter + '. ' + text);\n          }\n          else if (blockType === 'code-block')       parts.push('\\`\\`\\`\\\\n' + text + '\\\\n\\`\\`\\`');\n          else                                       parts.push(text);\n        }\n\n        return [{\n          title,\n          author: screenName,\n          content: parts.join('\\\\n\\\\n') || legacy.full_text || '',\n          url: 'https://x.com/' + screenName + '/status/' + tweetId,\n        }];\n      }\n    `));\n        if (!Array.isArray(rawResult) && !isPlainObject(rawResult)) {\n            throw new CommandExecutionError('Twitter article response payload is malformed');\n        }\n        if (rawResult?.httpStatus) {\n            const message = describeTwitterApiError('TweetResultByRestId', rawResult.httpStatus);\n            if (rawResult.httpStatus === 401 || rawResult.httpStatus === 403) {\n                throw new AuthRequiredError('x.com', message);\n            }\n            throw new CommandExecutionError(message);\n        }\n        if (rawResult?.error) {\n            throw new CommandExecutionError(rawResult.error + (rawResult.hint ? ` (${rawResult.hint})` : ''));\n        }\n        if (!Array.isArray(rawResult)) {\n            throw new CommandExecutionError('Twitter article response payload is malformed');\n        }\n        return rawResult;\n    }\n});\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/article.js#L228-L264","documentation":"After the in-page API call for TweetResultByRestId, the result must be either an array or a plain object. Anything else (undefined, null, string, number) means the page script failed to return a usable payload, so a CommandExecutionError 'Twitter article response payload is malformed' is thrown. This distinguishes a broken browser-side execution from an actual API error (handled by the httpStatus/error branches).","triggerScenarios":"The page.evaluate script returns undefined or a primitive — e.g. the evaluate was interrupted, the injected script failed silently, or the browser wrapper returned a non-serializable result.","commonSituations":"X page not fully loaded so the injected script bailed, browser navigation/reload mid-evaluate, extension interference with page scripts, or adapter page scripts breaking after X front-end changes.","solutions":["Retry the command — often the page just wasn't ready","Ensure a stable network connection and let the page load fully (the command waits ~3s; slow pages may need retry)","Disable interfering browser extensions in the CLI's profile","If persistent, update the adapter's injected TweetResultByRestId script to match current X page behavior"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isPlainObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }\nfunction isUsableTweetPayload(v) { return Array.isArray(v) || isPlainObject(v); }","tryCatchPattern":"try {\n  await articleCmd({ tweetId });\n} catch (err) {\n  if (err.message.includes('payload is malformed')) {\n    console.error('Browser-side script returned unusable data — retry or update adapter scripts');\n  } else throw err;\n}","preventionTips":["Retry — the X page may not have been fully loaded","Keep browser extensions from interfering with page scripts","Update adapter injected scripts when X's front-end changes","Ensure stable connectivity so evaluates are not interrupted"],"tags":["browser","api","payload"],"backgroundTag":"malformed-api-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}