{"record":{"id":"090e15b60484b52d","repo":"jackwener/OpenCLI","slug":"draft-id-was-not-found-in-drafttype-drafts","errorCode":null,"errorMessage":"Draft ${id} was not found in ${draftType} drafts. Run opencli xiaohongshu drafts --type ${draftType} to list current ids.","messagePattern":"Draft (.+?) was not found in (.+?) drafts\\. Run opencli xiaohongshu drafts --type (.+?) to list current ids\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/draft-delete.js","lineNumber":78,"sourceCode":"    description: '删除一条小红书本地草稿',\n    domain: 'creator.xiaohongshu.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    navigateBefore: false,\n    args: [\n        { name: 'id', positional: true, required: true, help: 'Draft id returned by `opencli xiaohongshu drafts`' },\n        { name: 'type', default: 'image', help: 'Draft type: image, video, article, audio' },\n        { name: 'execute', type: 'bool', default: false, help: 'Actually delete the local draft. Default is dry-run verification only.' },\n    ],\n    columns: ['status', 'id', 'type', 'message'],\n    func: async (page, kwargs) => {\n        const id = normalizeDraftId(kwargs.id);\n        const draftType = normalizeDraftType(kwargs.type);\n        const execute = kwargs.execute === true;\n        await ensureDraftDbPage(page);\n        const entries = await readDraftEntries(page, draftType);\n        const entry = findDraftEntry(entries, id);\n        if (!entry) throw draftNotFound(id, draftType, 'xiaohongshu/draft-delete');\n        const row = normalizeDraftRecord(entry.row, entry.key, draftType, 1);\n        if (!execute) {\n            return [{\n                status: 'dry-run',\n                id: row.id,\n                type: draftType,\n                message: 'Draft exists. Re-run with --execute to delete.',\n            }];\n        }\n        const storeName = STORE_NAME_MAP[draftType];\n        const result = unwrapBrowserResult(await page.evaluate(deleteDraftScript(storeName, entry.key)));\n        if (!result?.ok) {\n            throw new CommandExecutionError(result?.error || `Failed to delete draft ${row.id}`);\n        }\n        if (!result.deleted) {\n            throw new CommandExecutionError(`Draft ${row.id} still exists after delete`);\n        }\n        return [{","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/draft-delete.js#L60-L96","documentation":"draftNotFound is thrown when the requested draft id does not exist among the entries read from the Xiaohongshu draft database for the given draft type. The command aborts before any delete, and the message points to the drafts listing command to discover valid ids.","triggerScenarios":"Calling the xiaohongshu draft-delete command (clis/xiaohongshu/draft-delete.js) with an --id that is absent from readDraftEntries results for the given --type.","commonSituations":"Stale/hardcoded id after the draft was already deleted; wrong --type so the id is looked up in the wrong draft collection; typo'd or un-normalized id; draft db page not in sync.","solutions":["Run 'opencli xiaohongshu drafts --type <type>' to list current ids and copy the correct one","Confirm the --type matches the draft kind the id belongs to","Check the draft wasn't already deleted (list first)","Verify id normalization — pass the id exactly as listed"],"exampleFix":"// before\nopencli xiaohongshu draft-delete --id draft_999 --type note\n// after: list to get a valid id first\nopencli xiaohongshu drafts --type note\nopencli xiaohongshu draft-delete --id <validId> --type note --execute","handlingStrategy":"validation","validationCode":"const drafts = await opencli xiaohongshu drafts --type type;\nif (!drafts.some(d => d.id === targetId)) throw new Error(`Draft ${targetId} not found in ${type} drafts`);","typeGuard":"function draftExists(drafts, id) { return Array.isArray(drafts) && drafts.some(d => d && d.id === id); }","tryCatchPattern":"try {\n  await opencli xiaohongshu draft-delete --id id --type type --execute;\n} catch (e) {\n  if (/was not found in .* drafts/.test(e.message)) {\n    const list = await opencli xiaohongshu drafts --type type;\n    // pick a valid id from list and retry, or surface to the user\n  } else throw e;\n}","preventionTips":["Always list current ids before delete operations","Pass --type matching the draft kind","Treat ids as ephemeral — re-fetch after any mutation","Use dry-run first to confirm the id resolves"],"tags":["not-found","draft","xiaohongshu"],"backgroundTag":"resource-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}