jackwener/OpenCLI · error · ArgumentError
xianyu publish condition must be one of: ${CONDITION_CHOICES
Error message
xianyu publish condition must be one of: ${CONDITION_CHOICES.join(', ')} What it means
validateCondition throws ArgumentError when the condition string is not exactly one of the five accepted values: 全新, 几乎全新, 轻微使用, 明显使用, 老旧. The check is an exact includes() match against the CONDITION_CHOICES array, so any variation in wording, case, or whitespace fails.
Source
Thrown at clis/xianyu/publish.js:52
function parsePositivePrice(value, label) {
if (value == null || String(value).trim() === '') {
return null;
}
const text = String(value).trim();
if (!/^\d+(?:\.\d{1,2})?$/.test(text)) {
throw new ArgumentError(`xianyu publish ${label} must be a positive price with at most 2 decimals`);
}
const price = Number(text);
if (!Number.isFinite(price) || price <= 0) {
throw new ArgumentError(`xianyu publish ${label} must be a positive price`);
}
return text;
}
function validateCondition(value) {
const condition = requireText(value, 'condition');
if (!CONDITION_CHOICES.includes(condition)) {
throw new ArgumentError(`xianyu publish condition must be one of: ${CONDITION_CHOICES.join(', ')}`);
}
return condition;
}
function validateImagePaths(raw) {
if (!raw) return [];
const paths = String(raw).split(',').map((item) => item.trim()).filter(Boolean);
if (paths.length === 0) return [];
if (paths.length > MAX_IMAGES) {
throw new ArgumentError(`xianyu publish images supports at most ${MAX_IMAGES} files`);
}
return paths.map((item) => {
const absPath = path.resolve(item);
const ext = path.extname(absPath).toLowerCase();
if (!SUPPORTED_IMAGE_EXTENSIONS.has(ext)) {
throw new ArgumentError(`Unsupported image format "${ext}". Supported: jpg, jpeg, png, webp`);
}
const stat = fs.statSync(absPath, { throwIfNoEntry: false });View on GitHub (pinned to 49907e53dc)
Solutions
- Use one of the exact strings: '全新', '几乎全新', '轻微使用', '明显使用', '老旧'
- Trim and map your UI's condition values to the allowed choices before calling
- Import and iterate CONDITION_CHOICES from the module instead of hardcoding strings
Example fix
// before
await publish({ condition: 'new' });
// after
await publish({ condition: '全新' }); Defensive patterns
Strategy: validation
Validate before calling
const CHOICES = ['全新', '几乎全新', '轻微使用', '明显使用', '老旧'];
if (!CHOICES.includes(String(condition).trim())) {
throw new Error(`condition must be one of: ${CHOICES.join(', ')}`);
} Type guard
function isValidCondition(v) {
return ['全新', '几乎全新', '轻微使用', '明显使用', '老旧'].includes(v);
} Try / catch
try {
await publish({ condition });
} catch (e) {
if (e instanceof ArgumentError && /condition must be one of/.test(e.message)) {
console.error(`Invalid condition "${condition}"; allowed: 全新/几乎全新/轻微使用/明显使用/老旧`);
} else throw e;
} Prevention
- Define condition options as a shared constant, not string literals
- Map UI/locale values to the Chinese labels in one place
- Exact-match: beware whitespace and half/full-width characters
When it happens
Trigger: Calling normalizePublishArgs with kwargs.condition set to anything other than exactly one of ['全新','几乎全新','轻微使用','明显使用','老旧'] — e.g. English 'new'/'used', 'almost new', or values with extra whitespace.
Common situations: English-language codebases passing 'new'/'used' instead of Chinese labels, copy-paste from docs with different wording, or UI code sending raw user input without mapping to the Chinese choices.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ${label} must be one of: ${Object.keys(choices).join(', ')}
- ${label} must be one of: ${choices.join(', ')}
- rest-countries region "${value}" is not recognised
- unsupported notification type: ${value}
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/404eb13663ce21f5.
Report an issue: GitHub.