jackwener/OpenCLI · error · CommandExecutionError

${label}: could not verify current composer media count

Error message

${label}: could not verify current composer media count

What it means

assertComposerMediaCount calls currentComposerMediaCount to count visible media items in the composer. If the count query returns nothing usable (no numeric count), it throws this error — the media count could not be verified at all, distinct from the count being too low.

Source

Thrown at clis/xiaohongshu/publish.js:1038

        for (const el of Array.from(root.querySelectorAll('img, video, canvas, [style*="background-image"]'))) {
          if (!visibleMedia(el)) continue;
          const rect = el.getBoundingClientRect();
          const src = el.currentSrc || el.src || el.getAttribute('src') || el.style?.backgroundImage || '';
          const key = src || String(Math.round(rect.left)) + ':' + String(Math.round(rect.top));
          if (seen.has(key)) continue;
          seen.add(key);
          count += 1;
        }
      }
      return { ok: true, count };
    })()
  `);
    return unwrapBrowserResult(result);
}
async function assertComposerMediaCount(page, expectedCount, label) {
    const state = await currentComposerMediaCount(page);
    if (!state || typeof state.count !== 'number') {
        throw new CommandExecutionError(`${label}: could not verify current composer media count`);
    }
    if (state.count < expectedCount) {
        await page.screenshot({ path: '/tmp/xhs_publish_media_debug.png' });
        throw new CommandExecutionError(`${label}: expected at least ${expectedCount} visible media item(s), got ${state.count}. ` +
            'Debug screenshot: /tmp/xhs_publish_media_debug.png');
    }
}
/**
 * Drive the full 文字配图 sub-flow: entry → type cards → 生成图片 → pick style → 下一步.
 * Leaves the page on the standard editor (caller then runs waitForEditForm).
 */
async function runTextImageFlow(page, cards, cardStyle) {
    const entry = await clickByText(page, TEXT_IMAGE_ENTRY_LABEL);
    if (!entry?.ok) {
        await page.screenshot({ path: '/tmp/xhs_publish_textimage_debug.png' });
        throw new CommandExecutionError(`文字配图: could not click "${TEXT_IMAGE_ENTRY_LABEL}" entry. ` +
            'Debug: /tmp/xhs_publish_textimage_debug.png');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Add a wait for the editor/composer to render before media-count assertions run.
  2. Retry the publish — transient evaluate failures are common.
  3. Check the browser session is still alive (a dead session makes every evaluate fail).
  4. If persistent, update currentComposerMediaCount's selectors for the current XHS composer DOM.

Example fix

// before
await assertComposerMediaCount(page, media.length, "发布");
// after
await page.wait({ time: 2.0 }); // ensure composer rendered
try {
  await assertComposerMediaCount(page, media.length, "发布");
} catch (e) {
  if (!/could not verify/.test(e.message)) throw e;
  await page.wait({ time: 3.0 });
  await assertComposerMediaCount(page, media.length, "发布");
}
Defensive patterns

Strategy: retry

Validate before calling

await page.wait({ time: 2.0 }); // composer must be rendered before counting

Type guard

null

Try / catch

try { await assertComposerMediaCount(page, n, label); }
catch (e) {
  if (/could not verify/.test(e.message)) {
    await page.wait({ time: 3.0 });
    await assertComposerMediaCount(page, n, label);
  } else throw e;
}

Prevention

When it happens

Trigger: currentComposerMediaCount's page.evaluate returns null/undefined/non-numeric — evaluate threw and was swallowed, the composer DOM selectors matched nothing, or the browser result could not be unwrapped.

Common situations: Publish page not fully loaded when the assertion runs; XHS DOM restructure broke the media-count selectors; browser evaluate failed due to a closed CDP session or closed shadow-root access assumptions; running against a step where no composer exists.

Related errors


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