{"record":{"id":"8a98a2ee01ce726f","repo":"jackwener/OpenCLI","slug":"context-returned-a-malformed-result-8a98a2","errorCode":null,"errorMessage":"${context} returned a malformed result.","messagePattern":"(.+?) returned a malformed result\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/post.js","lineNumber":47,"sourceCode":"        }\n        const stat = fs.statSync(absPath, { throwIfNoEntry: false });\n        if (!stat || !stat.isFile()) {\n            throw new CommandExecutionError(`Not a valid file: ${absPath}`);\n        }\n        return absPath;\n    });\n}\n\nfunction isUnsupportedInsertTextError(err) {\n    const msg = err instanceof Error ? err.message : String(err);\n    const lower = msg.toLowerCase();\n    return lower.includes('unknown action') || lower.includes('not supported') || lower.includes('inserttext returned no inserted flag');\n}\n\nfunction requirePostActionResult(value, context) {\n    const result = unwrapBrowserResult(value);\n    if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.ok !== 'boolean') {\n        throw new CommandExecutionError(`${context} returned a malformed result.`);\n    }\n    if (Object.prototype.hasOwnProperty.call(result, 'message') && result.message != null && typeof result.message !== 'string') {\n        throw new CommandExecutionError(`${context} returned a malformed message.`);\n    }\n    if (Object.prototype.hasOwnProperty.call(result, 'error') && result.error != null && typeof result.error !== 'string') {\n        throw new CommandExecutionError(`${context} returned a malformed error.`);\n    }\n    return result;\n}\n\nfunction validateSubmitStatusPair(result) {\n    if ((result.id && !result.url) || (!result.id && result.url)) {\n        throw new CommandExecutionError('Twitter post completion returned only one of id/url.');\n    }\n    if (!result.id && !result.url) return;\n    if (typeof result.id !== 'string' || !/^\\d+$/.test(result.id)) {\n        throw new CommandExecutionError('Twitter post completion returned a malformed status id.');\n    }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/post.js#L29-L65","documentation":"requirePostActionResult validates every value returned from page.evaluate() inside the twitter post CLI. If the unwrapped browser result is not a plain object with a boolean `ok` field (e.g. null, an array, undefined, or a non-object), the helper throws this CommandExecutionError prefixed with the caller-provided context string. It exists to catch browser-side scripts that silently returned nothing or returned an unexpected shape instead of the { ok: boolean } contract.","triggerScenarios":"Any of focusComposer, verifyComposerText, insertComposerText, waitForImageUpload, upload, or clickResult passing an evaluate() result through requirePostActionResult where unwrapBrowserResult yields null/undefined, an Array, a non-object, or an object whose `ok` property is not a boolean — typically because the page script threw before returning, the page navigated mid-evaluate, or the injected script's return was serialized away.","commonSituations":"X/Twitter DOM or bundle changes causing the in-page IIFE to crash before returning; page navigation or dialog closing during evaluate; a browser extension or CSP blocking script execution so evaluate returns undefined; running against a stale/closed tab where evaluate resolves to undefined.","solutions":["Re-run the command on a fresh, loaded x.com page — transient evaluate failures usually resolve on retry","Update the twitter CLI if X changed its DOM, since the in-page script may be crashing before it can return { ok }","Log the raw value passed to requirePostActionResult to see what unwrapBrowserResult received","Ensure no navigation, alert dialogs, or redirects interrupt the composer page while the command runs"],"exampleFix":"// before: raw evaluate result fed straight in\nconst result = requirePostActionResult(await page.evaluate(script), 'Focus composer');\n// after: guard against undefined/null before validating\nconst raw = await page.evaluate(script);\nif (raw == null) throw new CommandExecutionError('Focus composer: page returned nothing (reload and retry).');\nconst result = requirePostActionResult(raw, 'Focus composer');","handlingStrategy":"type-guard","validationCode":"function isPlainPostResult(v) { return v != null && typeof v === 'object' && !Array.isArray(v) && typeof v.ok === 'boolean'; }\nif (!isPlainPostResult(raw)) throw new Error('browser returned malformed result; reload page and retry');","typeGuard":"function isPostActionResult(v) { return typeof v === 'object' && v !== null && !Array.isArray(v) && 'ok' in v && typeof v.ok === 'boolean'; }","tryCatchPattern":"try {\n  const result = requirePostActionResult(await page.evaluate(script), 'Focus composer');\n} catch (e) {\n  if (String(e.message).includes('returned a malformed result')) { await page.reload(); return retry(); }\n  throw e;\n}","preventionTips":["Reload the x.com page before posting if the tab has been open a long time","Avoid navigating or closing dialogs while a post command runs","Log raw evaluate results when debugging DOM changes","Keep the CLI updated against current X DOM structure"],"tags":["browser-automation","type-validation","x-twitter"],"backgroundTag":"malformed-browser-evaluate-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}