{"record":{"id":"404eb13663ce21f5","repo":"jackwener/OpenCLI","slug":"xianyu-publish-condition-must-be-one-of-conditi","errorCode":null,"errorMessage":"xianyu publish condition must be one of: ${CONDITION_CHOICES.join(', ')}","messagePattern":"xianyu publish condition must be one of: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/publish.js","lineNumber":52,"sourceCode":"function parsePositivePrice(value, label) {\n    if (value == null || String(value).trim() === '') {\n        return null;\n    }\n    const text = String(value).trim();\n    if (!/^\\d+(?:\\.\\d{1,2})?$/.test(text)) {\n        throw new ArgumentError(`xianyu publish ${label} must be a positive price with at most 2 decimals`);\n    }\n    const price = Number(text);\n    if (!Number.isFinite(price) || price <= 0) {\n        throw new ArgumentError(`xianyu publish ${label} must be a positive price`);\n    }\n    return text;\n}\n\nfunction validateCondition(value) {\n    const condition = requireText(value, 'condition');\n    if (!CONDITION_CHOICES.includes(condition)) {\n        throw new ArgumentError(`xianyu publish condition must be one of: ${CONDITION_CHOICES.join(', ')}`);\n    }\n    return condition;\n}\n\nfunction validateImagePaths(raw) {\n    if (!raw) return [];\n    const paths = String(raw).split(',').map((item) => item.trim()).filter(Boolean);\n    if (paths.length === 0) return [];\n    if (paths.length > MAX_IMAGES) {\n        throw new ArgumentError(`xianyu publish images supports at most ${MAX_IMAGES} files`);\n    }\n    return paths.map((item) => {\n        const absPath = path.resolve(item);\n        const ext = path.extname(absPath).toLowerCase();\n        if (!SUPPORTED_IMAGE_EXTENSIONS.has(ext)) {\n            throw new ArgumentError(`Unsupported image format \"${ext}\". Supported: jpg, jpeg, png, webp`);\n        }\n        const stat = fs.statSync(absPath, { throwIfNoEntry: false });","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/publish.js#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait publish({ condition: 'new' });\n// after\nawait publish({ condition: '全新' });","handlingStrategy":"validation","validationCode":"const CHOICES = ['全新', '几乎全新', '轻微使用', '明显使用', '老旧'];\nif (!CHOICES.includes(String(condition).trim())) {\n  throw new Error(`condition must be one of: ${CHOICES.join(', ')}`);\n}","typeGuard":"function isValidCondition(v) {\n  return ['全新', '几乎全新', '轻微使用', '明显使用', '老旧'].includes(v);\n}","tryCatchPattern":"try {\n  await publish({ condition });\n} catch (e) {\n  if (e instanceof ArgumentError && /condition must be one of/.test(e.message)) {\n    console.error(`Invalid condition \"${condition}\"; allowed: 全新/几乎全新/轻微使用/明显使用/老旧`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["validation","argument-error","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}