jackwener/OpenCLI · error · CommandExecutionError

${result.after} ${draftType} drafts still exist after clear

Error message

${result.after} ${draftType} drafts still exist after clear

What it means

This CommandExecutionError is thrown by draft-clear.js after running the in-page clearDraftsScript with --execute when the script reports a non-zero remaining draft count in the IndexedDB stores. It means the clear command ran but failed to actually empty the target draft stores, so the CLI aborts rather than reporting success.

Source

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

    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. Close other tabs/session windows that may be recreating drafts, then re-run with --execute
  2. Run without --execute first to verify the count drops to 0 after a clear attempt
  3. Check that draftType's store names in STORE_NAME_MAP cover all stores holding drafts
  4. Manually inspect the IndexedDB stores via DevTools and clear them, then re-run the command

Example fix

// before
await runClear({ execute: true }); // throws 'N video drafts still exist after clear'
// after
// close other XHS tabs / stop background draft writers, then:
const dry = await runClear({ execute: false });
if (Number(dry[0].count) > 0) await runClear({ execute: true });
Defensive patterns

Strategy: validation

Validate before calling

const dry = await draftClear({ type: 'video', execute: false });
if (Number(dry[0].count) === 0) console.log('nothing to clear');
// close other XHS tabs before running with --execute

Try / catch

try {
  await draftClear({ type: 'video', execute: true });
} catch (e) {
  if (/still exist after clear/.test(e.message)) {
    const remaining = Number(e.message.split(' ')[0]);
    console.error(`Clear incomplete: ${remaining} drafts remain; close other tabs and retry`);
  } else throw e;
}

Prevention

When it happens

Trigger: Running the clear command with --execute when the browser page's IndexedDB still contains drafts after the clear script ran — e.g. drafts being re-created concurrently by an open XHS page, storeNames not covering all relevant object stores, or the clear script silently skipping records.

Common situations: User has the Xiaohongshu creator page open in another tab that keeps writing new drafts while the clear runs; a XHS version change moved drafts to a store not included in STORE_NAME_MAP; stale page state after login changes.

Related errors


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