{"record":{"id":"83efc6c9c0bcf111","repo":"jackwener/OpenCLI","slug":"unsupported-draft-type-raw-expected-one-of","errorCode":null,"errorMessage":"Unsupported draft type \"${raw}\". Expected one of: ${choices}","messagePattern":"Unsupported draft type \"(.+?)\"\\. Expected one of: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/draft-utils.js","lineNumber":29,"sourceCode":"\nexport function unwrapBrowserResult(value) {\n    if (\n        value\n        && typeof value === 'object'\n        && typeof value.session === 'string'\n        && Object.prototype.hasOwnProperty.call(value, 'data')\n    ) {\n        return value.data;\n    }\n    return value;\n}\n\nexport function normalizeDraftType(value, { allowAll = false } = {}) {\n    const raw = String(value ?? 'image').trim().toLowerCase();\n    if (allowAll && raw === 'all') return raw;\n    if (!STORE_NAME_MAP[raw]) {\n        const choices = allowAll ? 'image, video, article, audio, all' : Object.keys(STORE_NAME_MAP).join(', ');\n        throw new ArgumentError(`Unsupported draft type \"${raw}\". Expected one of: ${choices}`);\n    }\n    return raw;\n}\n\nexport function normalizeDraftId(value) {\n    const id = String(value ?? '').trim();\n    if (!id) throw new ArgumentError('Draft id is required');\n    return id;\n}\n\nexport function encodeDraftKey(key) {\n    const type = typeof key;\n    if (type === 'string') return `s:${key}`;\n    if (type === 'number') return `n:${String(key)}`;\n    if (type === 'boolean') return `b:${String(key)}`;\n    try {\n        return `j:${encodeURIComponent(JSON.stringify(key))}`;\n    }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/draft-utils.js#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnode draft-clear.js --type img --execute\n// after\nnode draft-clear.js --type image --execute","handlingStrategy":"validation","validationCode":"const VALID = ['image', 'video', 'article', 'audio'];\nconst t = String(process.argv.type ?? '').trim().toLowerCase();\nif (!VALID.includes(t) && t !== 'all') throw new Error(`Bad --type \"${t}\"; use: ${VALID.join(', ')}`);","typeGuard":"function isDraftType(v) {\n  return typeof v === 'string' && ['image', 'video', 'article', 'audio'].includes(v.trim().toLowerCase());\n}","tryCatchPattern":"try {\n  await draftClear({ type: rawType, execute: true });\n} catch (e) {\n  if (e instanceof ArgumentError && /Unsupported draft type/.test(e.message)) {\n    console.error(e.message); // lists the valid choices\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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"],"tags":["cli","argument-validation","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}