jackwener/OpenCLI · error · CommandExecutionError

${context} returned a malformed result.

Error message

${context} returned a malformed result.

What it means

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.

Source

Thrown at clis/twitter/reply.js:34

function buildReplyComposerUrl(rawUrl) {
    // Replaces the legacy local extractTweetId which used `/\/status\/(\d+)/`
    // (silent: matched `/status/1234567` on substring `/status/123` and
    // accepted any host). parseTweetUrl bubbles ArgumentError on
    // malformed/off-domain inputs.
    const target = parseTweetUrl(rawUrl);
    return `https://x.com/compose/post?in_reply_to=${target.id}`;
}

function isPromiseCollectedError(err) {
    const msg = err instanceof Error ? err.message : String(err);
    return msg.includes('Promise was collected');
}

function requireReplyActionResult(value, context) {
    const result = unwrapBrowserResult(value);
    if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.ok !== 'boolean') {
        throw new CommandExecutionError(`${context} returned a malformed result.`);
    }
    if (Object.prototype.hasOwnProperty.call(result, 'message') && result.message != null && typeof result.message !== 'string') {
        throw new CommandExecutionError(`${context} returned a malformed message.`);
    }
    if (Object.prototype.hasOwnProperty.call(result, 'url') && result.url != null && typeof result.url !== 'string') {
        throw new CommandExecutionError(`${context} returned a malformed status url.`);
    }
    return result;
}

function validateReplyStatusUrl(result) {
    if (!result.url) return;
    let url;
    try {
        url = new URL(result.url);
    } catch {
        throw new CommandExecutionError('Twitter reply completion returned a malformed status url.');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the reply step once — transient page-context timing is the most common cause
  2. Update the library to match any x.com reply-dialog DOM changes that break the in-page script
  3. Disable extensions/interceptors in the automation profile that could alter evaluate results
  4. Wrap reply actions in try-catch for CommandExecutionError and log the raw value to diagnose the shape mismatch

Example fix

// caller-side guard
let result;
try {
  result = await replyFlow.clickReplyButton(page);
} catch (e) {
  if (String(e.message).includes('returned a malformed result')) {
    await page.reload();
    result = await replyFlow.clickReplyButton(page); // one retry
  } else throw e;
}
Defensive patterns

Strategy: type-guard

Type guard

function isReplyActionResult(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v) && typeof v.ok === 'boolean';
}

Try / catch

try {
  await replyFlow.clickReplyButton(page);
} catch (e) {
  if (e instanceof CommandExecutionError && /returned a malformed result/.test(e.message)) {
    await page.reload(); // restore a clean page context, then retry once
    return replyFlow.clickReplyButton(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/07b7a9526b334fa0. Report an issue: GitHub.