{"record":{"id":"3742fe1bc5962232","repo":"jackwener/OpenCLI","slug":"failed-to-execute-clear-count-draftty","errorCode":null,"errorMessage":"Failed to ${execute ? 'clear' : 'count'} ${draftType} drafts","messagePattern":"Failed to (.+?) (.+?) drafts","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/draft-clear.js","lineNumber":79,"sourceCode":"    access: 'write',\n    description: '清空小红书本地草稿',\n    domain: 'creator.xiaohongshu.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    navigateBefore: false,\n    args: [\n        { name: 'type', default: 'image', help: 'Draft type: image, video, article, audio, all' },\n        { name: 'execute', type: 'bool', default: false, help: 'Actually clear local drafts. Default is dry-run count only.' },\n    ],\n    columns: ['status', 'type', 'count', 'message'],\n    func: async (page, kwargs) => {\n        const draftType = normalizeDraftType(kwargs.type, { allowAll: true });\n        const execute = kwargs.execute === true;\n        const storeNames = draftType === 'all' ? Object.values(STORE_NAME_MAP) : [STORE_NAME_MAP[draftType]];\n        await ensureDraftDbPage(page);\n        const result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, execute)));\n        if (!result?.ok) {\n            throw new CommandExecutionError(result?.error || `Failed to ${execute ? 'clear' : 'count'} ${draftType} drafts`);\n        }\n        if (execute && Number(result.after) !== 0) {\n            throw new CommandExecutionError(`${result.after} ${draftType} drafts still exist after clear`);\n        }\n        return [{\n            status: execute ? 'cleared' : 'dry-run',\n            type: draftType,\n            count: execute ? Number(result.cleared || 0) : Number(result.before || 0),\n            message: execute ? 'Drafts cleared.' : 'Drafts counted. Re-run with --execute to clear.',\n        }];\n    },\n});\n","sourceCodeStart":61,"sourceCodeEnd":92,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/draft-clear.js#L61-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If result.error was included, fix the underlying cause it reports; otherwise inspect the draft DB manually (DevTools > Application > IndexedDB) for schema changes.","Run in dry-run mode first (execute: false) to confirm counting works before attempting a clear.","Update STORE_NAME_MAP / clearDraftsScript if store names or the DB version changed.","Close other tabs holding the draft DB open and retry."],"exampleFix":"// before\nconst result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, true)));\n// after\nconst count = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, false))); // dry-run first\nif (count?.ok) {\n  const result = unwrapBrowserResult(await page.evaluate(clearDraftsScript(storeNames, true)));\n}","handlingStrategy":"try-catch","validationCode":"// Dry-run first to validate the draft DB is reachable and stores resolve\nconst dry = await cli.run('xiaohongshu/draft-clear', { type: 'all', execute: false });\nif (!dry || dry.error) throw new Error('draft DB not accessible');","typeGuard":"function isClearResultOk(r) { return r !== null && typeof r === 'object' && r.ok === true; }","tryCatchPattern":"try {\n  await cli.run('xiaohongshu/draft-clear', { type: 'image', execute: true });\n} catch (err) {\n  if (/Failed to (clear|count)/.test(err.message)) {\n    // inspect draft DB schema/store names, close other tabs, then retry\n    return retryDraftClear();\n  }\n  throw err;\n}","preventionTips":["Always dry-run (execute: false) before executing a clear.","Verify the draft IndexedDB store names in DevTools after Xiaohongshu updates.","Close other tabs holding the draft DB connection before clearing.","Capture result.error from the page script rather than relying on the generic fallback message."],"tags":["indexeddb","drafts","web-automation","cli"],"backgroundTag":"indexeddb-operation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}