jackwener/OpenCLI · error · ArgumentError
Unsupported draft type "${raw}". Expected one of: ${choices}
Error message
Unsupported draft type "${raw}". Expected one of: ${choices} What it means
normalizeDraftType validates the --type/--draft-type user input against STORE_NAME_MAP and throws ArgumentError when the value is not a known draft type. With allowAll, 'all' is accepted and the choice list includes it; otherwise only the concrete store types are allowed.
Source
Thrown at clis/xiaohongshu/draft-utils.js:29
export function unwrapBrowserResult(value) {
if (
value
&& typeof value === 'object'
&& typeof value.session === 'string'
&& Object.prototype.hasOwnProperty.call(value, 'data')
) {
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))}`;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Use one of: image, video, article, audio (case/whitespace insensitive)
- Include 'all' only if the command supports it (allowAll)
- Trim/normalize values coming from config files or environment variables before passing them
- Run the command with --help or check STORE_NAME_MAP in draft-utils.js for the current list
Example fix
// before node draft-clear.js --type img --execute // after node draft-clear.js --type image --execute
Defensive patterns
Strategy: validation
Validate before calling
const VALID = ['image', 'video', 'article', 'audio'];
const t = String(process.argv.type ?? '').trim().toLowerCase();
if (!VALID.includes(t) && t !== 'all') throw new Error(`Bad --type "${t}"; use: ${VALID.join(', ')}`); Type guard
function isDraftType(v) {
return typeof v === 'string' && ['image', 'video', 'article', 'audio'].includes(v.trim().toLowerCase());
} Try / catch
try {
await draftClear({ type: rawType, execute: true });
} catch (e) {
if (e instanceof ArgumentError && /Unsupported draft type/.test(e.message)) {
console.error(e.message); // lists the valid choices
process.exitCode = 2;
} else throw e;
} Prevention
- Keep a constant list of valid types in your wrapper scripts and validate before invoking
- Trim and lowercase any type value sourced from config/env/CLI
- Never guess type names from the XHS UI; use the documented store types
- Include 'all' only for commands that explicitly support it
When it happens
Trigger: Passing any type string other than image, video, article, audio (or 'all' when allowAll is set) to any draft command — e.g. --type Image with different casing is fine (lowercased), but --type vidoe, --type img, or an empty string ('') produce this error.
Common situations: Typo in the CLI flag value; scripting the CLI with a type name guessed from the UI ('img', 'note'); passing a value read from config/env that includes whitespace or quotes; older scripts using a type that was removed.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/83efc6c9c0bcf111.
Report an issue: GitHub.