jackwener/OpenCLI · error · EmptyResultError

Draft ${id} was not found in ${draftType} drafts. Run opencl

Error message

Draft ${id} was not found in ${draftType} drafts. Run opencli xiaohongshu drafts --type ${draftType} to list current ids.

What it means

draftNotFound is thrown when the requested draft id is absent from the Xiaohongshu draft database entries for the given draft type in the draft-open flow (clis/xiaohongshu/draft-open.js). The command cannot open a draft that doesn't resolve to an entry.

Source

Thrown at clis/xiaohongshu/draft-open.js:32

    name: 'draft-open',
    access: 'read',
    description: '读取一条小红书本地草稿详情',
    domain: 'creator.xiaohongshu.com',
    strategy: Strategy.COOKIE,
    browser: true,
    navigateBefore: false,
    args: [
        { name: 'id', positional: true, required: true, help: 'Draft id returned by `opencli xiaohongshu drafts`' },
        { name: 'type', default: 'image', help: 'Draft type: image, video, article, audio' },
    ],
    columns: ['id', 'type', 'title', 'updated_at', 'images', 'content'],
    func: async (page, kwargs) => {
        const id = normalizeDraftId(kwargs.id);
        const draftType = normalizeDraftType(kwargs.type);
        await ensureDraftDbPage(page);
        const entries = await readDraftEntries(page, draftType);
        const entry = findDraftEntry(entries, id);
        if (!entry) throw draftNotFound(id, draftType, 'xiaohongshu/draft-open');
        const row = normalizeDraftRecord(entry.row, entry.key, draftType, 1, { contentLimit: 500 });
        return [{
            id: row.id,
            type: row.type,
            title: row.title,
            updated_at: row.updated_at,
            images: row.images,
            content: row.text_preview,
        }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run 'opencli xiaohongshu drafts --type <type>' and use a currently listed id
  2. Confirm --type corresponds to the draft's actual kind
  3. Refresh the drafts database page and retry in case entries were stale
  4. Pass the id verbatim from the listing to avoid normalization mismatches

Example fix

// before
opencli xiaohongshu draft-open --id draft_123 --type note
// after
opencli xiaohongshu drafts --type note
opencli xiaohongshu draft-open --id <validId> --type note
Defensive patterns

Strategy: validation

Validate before calling

const drafts = await opencli xiaohongshu drafts --type type;
if (!drafts.some(d => d.id === targetId)) throw new Error(`Draft ${targetId} not found in ${type} drafts`);

Type guard

function draftExists(drafts, id) { return Array.isArray(drafts) && drafts.some(d => d && d.id === id); }

Try / catch

try {
  await opencli xiaohongshu draft-open --id id --type type;
} catch (e) {
  if (/was not found in .* drafts/.test(e.message)) {
    const list = await opencli xiaohongshu drafts --type type;
    // re-select a valid id and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the xiaohongshu draft-open command with an --id not present in readDraftEntries results for the given --type.

Common situations: Id taken from an old listing after the draft was deleted or edited; wrong --type passed so lookup misses; draft db page stale or partially loaded; id casing/format mismatch.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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