{"record":{"id":"1396e9074b068d45","repo":"jackwener/OpenCLI","slug":"result-after-drafttype-drafts-still-exist-af","errorCode":null,"errorMessage":"${result.after} ${draftType} drafts still exist after clear","messagePattern":"(.+?) (.+?) drafts still exist after clear","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/draft-clear.js","lineNumber":82,"sourceCode":"    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":64,"sourceCodeEnd":92,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/draft-clear.js#L64-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Close other tabs/session windows that may be recreating drafts, then re-run with --execute","Run without --execute first to verify the count drops to 0 after a clear attempt","Check that draftType's store names in STORE_NAME_MAP cover all stores holding drafts","Manually inspect the IndexedDB stores via DevTools and clear them, then re-run the command"],"exampleFix":"// before\nawait runClear({ execute: true }); // throws 'N video drafts still exist after clear'\n// after\n// close other XHS tabs / stop background draft writers, then:\nconst dry = await runClear({ execute: false });\nif (Number(dry[0].count) > 0) await runClear({ execute: true });","handlingStrategy":"validation","validationCode":"const dry = await draftClear({ type: 'video', execute: false });\nif (Number(dry[0].count) === 0) console.log('nothing to clear');\n// close other XHS tabs before running with --execute","typeGuard":null,"tryCatchPattern":"try {\n  await draftClear({ type: 'video', execute: true });\n} catch (e) {\n  if (/still exist after clear/.test(e.message)) {\n    const remaining = Number(e.message.split(' ')[0]);\n    console.error(`Clear incomplete: ${remaining} drafts remain; close other tabs and retry`);\n  } else throw e;\n}","preventionTips":["Always do a dry-run first to see how many drafts will be affected","Close other XHS browser tabs that can recreate drafts mid-clear","Keep STORE_NAME_MAP updated when XHS changes its IndexedDB schema","Re-run the dry-run after a clear to verify the count is 0"],"tags":["indexeddb","cli","drafts","state-inconsistency"],"backgroundTag":"drafts-still-exist-after-clear","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}