jackwener/OpenCLI · error · CommandExecutionError

${label} returned malformed rows

Error message

${label} returned malformed rows

What it means

normalizeConversationRows validates the rows array returned by the Grok history-collection script (used by validRows). If the evaluate result is not an array it throws CommandExecutionError('<label> returned malformed rows', 'Expected rows to be an array.'); individual entries must additionally be objects with a valid UUID-shaped Grok conversation id and a valid https://grok.com/c/<uuid> URL.

Source

Thrown at clis/grok/export-utils.js:56

    try {
        parsed = new URL(raw);
    } catch {
        throw makeError(`invalid url for conversation ${id}`);
    }
    const host = parsed.hostname.toLowerCase();
    const match = parsed.pathname.match(/^\/c\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/?$/i);
    if (parsed.protocol !== 'https:' || (host !== 'grok.com' && !host.endsWith('.grok.com')) || !match) {
        throw makeError(`invalid url for conversation ${id}`);
    }
    if (match[1].toLowerCase() !== id) {
        throw makeError(`url id mismatch for conversation ${id}`);
    }
    return `https://grok.com/c/${id}`;
}

export function normalizeConversationRows(rows, label) {
    if (!Array.isArray(rows)) {
        throw new CommandExecutionError(`${label} returned malformed rows`, 'Expected rows to be an array.');
    }
    return rows.map((row, index) => {
        if (!row || typeof row !== 'object' || Array.isArray(row)) {
            throw new CommandExecutionError(`${label} returned a malformed row`, `Row ${index + 1} is not an object.`);
        }
        const id = String(row.id || '').trim().toLowerCase();
        if (!GROK_CONVERSATION_ID_RE.test(id)) {
            throw new CommandExecutionError(`${label} returned a malformed row`, `Row ${index + 1} is missing a valid Grok conversation id.`);
        }
        return {
            id,
            title: row.title == null || row.title === '' ? '' : String(row.title),
            date: row.date == null || row.date === '' ? '' : String(row.date),
            url: normalizeGrokUrl(row.url, id, (reason) => new CommandExecutionError(`${label} returned a malformed row`, reason)),
        };
    });
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Confirm the automation browser is authenticated to grok.com and not showing a login or bot-check page, then re-run.
  2. Retry, or increase --max-scrolls, so the history list fully loads before rows are collected.
  3. If using a manifestPath instead, verify it is a JSON array exported by grok/export with id and grok.com/c/<uuid> url fields (manifest rows are validated by normalizeManifestRows).
  4. If it fails on every run, update the opencli Grok collection script — the site's DOM/URL format likely changed.

Example fix

// before (selector drift yields a non-array)
const rows = await page.evaluate(() => document.querySelectorAll('a[href^="/c/"]'));
// after (materialize into an array of plain objects)
const rows = await page.evaluate(() =>
  Array.from(document.querySelectorAll('a[href^="/c/"]'), (a) => ({
    id: a.href.split('/c/')[1] || '',
    title: a.textContent?.trim() || '',
    url: a.href,
  }))
);
Defensive patterns

Strategy: validation

Validate before calling

function looksLikeGrokRows(v) {
  const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
  return Array.isArray(v) && v.every((r) => r && typeof r === 'object' &&
    uuid.test(String(r.id || '')) && /^https:\/\/([a-z0-9-]+\.)?grok\.com\/c\/[0-9a-f-]{36}\/?$/i.test(String(r.url || '')));
}

Type guard

function isConversationRowArray(v) {
  return Array.isArray(v) && v.length > 0 && v.every((r) => r !== null && typeof r === 'object' && !Array.isArray(r));
}

Try / catch

try {
  const rows = await collectHistory(page, { offset, limit, maxScrolls });
} catch (err) {
  if (err instanceof CommandExecutionError && /malformed rows|malformed row/.test(err.message)) {
    // history DOM changed or page not loaded: re-authenticate, raise maxScrolls, or fall back to a manifestPath
    return runWithManifest(kwargs.manifestPath, { offset, limit });
  }
  throw err;
}

Prevention

When it happens

Trigger: collectHistory's page.evaluate returns null/undefined/a non-array (history never loaded, logged-out or bot-check page, evaluate interrupted), or returns an array whose entries are not objects, lack a UUID id, or carry a URL that is not a well-formed grok.com/c/<uuid> link.

Common situations: Grok UI redesign changing the DOM the scraper reads so the script returns a different shape; scraping while signed out or behind a Cloudflare challenge; version drift between the opencli Grok scripts and the live site; a conversation whose URL pattern changed (e.g. different path prefix) failing per-row validation.

Understand the failure class

Related errors


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