jackwener/OpenCLI · error · CommandExecutionError

Failed to ${execute ? 'clear' : 'count'} ${draftType} drafts

Error message

Failed to ${execute ? 'clear' : 'count'} ${draftType} drafts

What it means

CommandExecutionError thrown by the xiaohongshu/draft-clear command when the in-page IndexedDB draft-clearing script reports `ok: false`, or when no result.error message is available. The script either counted (execute=false) or deleted (execute=true) drafts in the given object stores and returned a failure flag, so the command surfaces a generic failure message naming the draft type and mode.

Source

Thrown at clis/xiaohongshu/draft-clear.js:79

    access: 'write',
    description: '清空小红书本地草稿',
    domain: 'creator.xiaohongshu.com',
    strategy: Strategy.COOKIE,
    browser: true,
    navigateBefore: false,
    args: [
        { name: 'type', default: 'image', help: 'Draft type: image, video, article, audio, all' },
        { name: 'execute', type: 'bool', default: false, help: 'Actually clear local drafts. Default is dry-run count only.' },
    ],
    columns: ['status', 'type', 'count', 'message'],
    func: async (page, kwargs) => {
        const draftType = normalizeDraftType(kwargs.type, { allowAll: true });
        const execute = kwargs.execute === true;
        const storeNames = draftType === 'all' ? Object.values(STORE_NAME_MAP) : [STORE_NAME_MAP[draftType]];
        await ensureDraftDbPage(page);
        const result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, execute)));
        if (!result?.ok) {
            throw new CommandExecutionError(result?.error || `Failed to ${execute ? 'clear' : 'count'} ${draftType} drafts`);
        }
        if (execute && Number(result.after) !== 0) {
            throw new CommandExecutionError(`${result.after} ${draftType} drafts still exist after clear`);
        }
        return [{
            status: execute ? 'cleared' : 'dry-run',
            type: draftType,
            count: execute ? Number(result.cleared || 0) : Number(result.before || 0),
            message: execute ? 'Drafts cleared.' : 'Drafts counted. Re-run with --execute to clear.',
        }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. If result.error was included, fix the underlying cause it reports; otherwise inspect the draft DB manually (DevTools > Application > IndexedDB) for schema changes.
  2. Run in dry-run mode first (execute: false) to confirm counting works before attempting a clear.
  3. Update STORE_NAME_MAP / clearDraftsScript if store names or the DB version changed.
  4. Close other tabs holding the draft DB open and retry.

Example fix

// before
const result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, true)));
// after
const count = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, false))); // dry-run first
if (count?.ok) {
  const result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, true)));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Dry-run first to validate the draft DB is reachable and stores resolve
const dry = await cli.run('xiaohongshu/draft-clear', { type: 'all', execute: false });
if (!dry || dry.error) throw new Error('draft DB not accessible');

Type guard

function isClearResultOk(r) { return r !== null && typeof r === 'object' && r.ok === true; }

Try / catch

try {
  await cli.run('xiaohongshu/draft-clear', { type: 'image', execute: true });
} catch (err) {
  if (/Failed to (clear|count)/.test(err.message)) {
    // inspect draft DB schema/store names, close other tabs, then retry
    return retryDraftClear();
  }
  throw err;
}

Prevention

When it happens

Trigger: Running `xiaohongshu draft-clear` when clearDraftsScript fails inside page.evaluate: the IndexedDB database or object stores (STORE_NAME_MAP) are missing/renamed, the DB is locked or in an upgrade state, ensureDraftDbPage opened the wrong DB version, or the browser denied the operation.

Common situations: Xiaohongshu changed its draft IndexedDB schema/store names; running with a page context where the draft DB was never created (no drafts ever saved), causing store lookups to fail; concurrent tabs holding the DB connection.

Related errors


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