{"record":{"id":"07b7a9526b334fa0","repo":"jackwener/OpenCLI","slug":"context-returned-a-malformed-result-07b7a9","errorCode":null,"errorMessage":"${context} returned a malformed result.","messagePattern":"(.+?) returned a malformed result\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/reply.js","lineNumber":34,"sourceCode":"\nfunction buildReplyComposerUrl(rawUrl) {\n    // Replaces the legacy local extractTweetId which used `/\\/status\\/(\\d+)/`\n    // (silent: matched `/status/1234567` on substring `/status/123` and\n    // accepted any host). parseTweetUrl bubbles ArgumentError on\n    // malformed/off-domain inputs.\n    const target = parseTweetUrl(rawUrl);\n    return `https://x.com/compose/post?in_reply_to=${target.id}`;\n}\n\nfunction isPromiseCollectedError(err) {\n    const msg = err instanceof Error ? err.message : String(err);\n    return msg.includes('Promise was collected');\n}\n\nfunction requireReplyActionResult(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, 'url') && result.url != null && typeof result.url !== 'string') {\n        throw new CommandExecutionError(`${context} returned a malformed status url.`);\n    }\n    return result;\n}\n\nfunction validateReplyStatusUrl(result) {\n    if (!result.url) return;\n    let url;\n    try {\n        url = new URL(result.url);\n    } catch {\n        throw new CommandExecutionError('Twitter reply completion returned a malformed status url.');\n    }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/reply.js#L16-L52","documentation":"CommandExecutionError thrown by requireReplyActionResult when a page.evaluate result for a reply action (clicked, insertReplyText, clickReplyButton, result) does not match the expected shape: it must be a non-null, non-array object with a boolean `ok` field (and optional string message/url). Anything else means the in-page script returned an unexpected value and the reply flow cannot proceed safely.","triggerScenarios":"unwrapBrowserResult yields null/undefined, an array, a primitive, or an object without a boolean ok — e.g. the injected reply script threw, returned undefined, or x.com page context changed the return value.","commonSituations":"x.com DOM changes causing the in-page script to bail out and return undefined; browser extension interference; evaluate result wrapping/serialization mismatch after a library or driver upgrade; timing issues where the script runs before the page context is ready.","solutions":["Retry the reply step once — transient page-context timing is the most common cause","Update the library to match any x.com reply-dialog DOM changes that break the in-page script","Disable extensions/interceptors in the automation profile that could alter evaluate results","Wrap reply actions in try-catch for CommandExecutionError and log the raw value to diagnose the shape mismatch"],"exampleFix":"// caller-side guard\nlet result;\ntry {\n  result = await replyFlow.clickReplyButton(page);\n} catch (e) {\n  if (String(e.message).includes('returned a malformed result')) {\n    await page.reload();\n    result = await replyFlow.clickReplyButton(page); // one retry\n  } else throw e;\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isReplyActionResult(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v) && typeof v.ok === 'boolean';\n}","tryCatchPattern":"try {\n  await replyFlow.clickReplyButton(page);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /returned a malformed result/.test(e.message)) {\n    await page.reload(); // restore a clean page context, then retry once\n    return replyFlow.clickReplyButton(page);\n  }\n  throw e;\n}","preventionTips":["Reload the page if evaluate results start failing shape checks","Disable extensions that tamper with page scripts/fetch","Keep the library updated when x.com reply-dialog DOM changes","Ensure the page is fully loaded before invoking reply actions"],"tags":["malformed-response","shape-validation","browser-automation","reply-flow"],"backgroundTag":"malformed-api-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}