jackwener/OpenCLI · error · ArgumentError
Draft id is required
Error message
Draft id is required
What it means
normalizeDraftId requires a non-empty draft id and throws ArgumentError when the value is missing, null, undefined, or only whitespace. The draft commands need an id to locate the specific record to inspect or delete.
Source
Thrown at clis/xiaohongshu/draft-utils.js:36
) {
return value.data;
}
return value;
}
export function normalizeDraftType(value, { allowAll = false } = {}) {
const raw = String(value ?? 'image').trim().toLowerCase();
if (allowAll && raw === 'all') return raw;
if (!STORE_NAME_MAP[raw]) {
const choices = allowAll ? 'image, video, article, audio, all' : Object.keys(STORE_NAME_MAP).join(', ');
throw new ArgumentError(`Unsupported draft type "${raw}". Expected one of: ${choices}`);
}
return raw;
}
export function normalizeDraftId(value) {
const id = String(value ?? '').trim();
if (!id) throw new ArgumentError('Draft id is required');
return id;
}
export function encodeDraftKey(key) {
const type = typeof key;
if (type === 'string') return `s:${key}`;
if (type === 'number') return `n:${String(key)}`;
if (type === 'boolean') return `b:${String(key)}`;
try {
return `j:${encodeURIComponent(JSON.stringify(key))}`;
}
catch {
return `s:${String(key)}`;
}
}
export function findDraftEntry(entries, id) {
return entries.find((entry) => encodeDraftKey(entry?.key) === id) || null;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a concrete draft id via the --id flag (obtain it from the list/count command output)
- Check that the upstream value producing the id is not empty/undefined before invoking
- Trim shell variables: node draft-delete.js --id "$ID" with ID verified non-empty
Example fix
// before
const id = cfg.lastDraft?.id; // undefined
await draftDelete({ id }); // throws 'Draft id is required'
// after
if (!cfg.lastDraft?.id) throw new Error('No draft id in config; run draft list first');
await draftDelete({ id: cfg.lastDraft.id }); Defensive patterns
Strategy: validation
Validate before calling
const id = String(opts.id ?? '').trim();
if (!id) throw new Error('Provide a non-empty --id (see draft list output)'); Type guard
function hasDraftId(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await draftDelete({ type: 'video', id, execute: true });
} catch (e) {
if (e instanceof ArgumentError && e.message === 'Draft id is required') {
console.error('Missing --id; run the list command to get draft ids');
} else throw e;
} Prevention
- Always pass --id explicitly; never rely on possibly-undefined variables
- Validate upstream data (previous command output) before using it as an id
- Trim shell variables and check non-empty before interpolation
- Fail fast in wrapper scripts when the id lookup step yields nothing
When it happens
Trigger: Invoking draft-delete (or similar) without --id, with --id="", or with a value consisting only of spaces; passing a variable that is undefined because an earlier lookup step failed or returned nothing.
Common situations: Scripting the CLI where the id comes from a previous command's JSON output that was empty; quoting mistakes in shell leaving an empty argument; forgetting the --id flag entirely.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a04a2d0d130c31cd.
Report an issue: GitHub.