{"record":{"id":"aa862ef9645c110d","repo":"jackwener/OpenCLI","slug":"xianyu-publish-price-cannot-be-empty","errorCode":null,"errorMessage":"xianyu publish price cannot be empty","messagePattern":"xianyu publish price cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/publish.js","lineNumber":81,"sourceCode":"    }\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 });\n        if (!stat || !stat.isFile()) {\n            throw new ArgumentError(`Not a valid image file: ${absPath}`);\n        }\n        return absPath;\n    });\n}\n\nfunction normalizePublishArgs(kwargs) {\n    const price = parsePositivePrice(kwargs.price, 'price');\n    if (price == null) {\n        throw new ArgumentError('xianyu publish price cannot be empty');\n    }\n    const normalized = {};\n    normalized.title = requireText(kwargs.title, 'title');\n    normalized.description = requireText(kwargs.description, 'description');\n    normalized.price = price;\n    normalized.condition = validateCondition(kwargs.condition);\n    normalized.category = requireText(kwargs.category, 'category');\n    normalized.original_price = parsePositivePrice(kwargs.original_price, 'original_price');\n    normalized.location = kwargs.location ? requireText(kwargs.location, 'location') : '';\n    normalized.images = validateImagePaths(kwargs.images);\n    return normalized;\n}\n\n// ===== 表单填充 evaluate scripts =====\n\nfunction buildFillFormEvaluate(data) {\n    return `\n    (() => {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/publish.js#L63-L99","documentation":"normalizePublishArgs throws ArgumentError when the price field is null/undefined after parsePositivePrice is called. parsePositivePrice throws on bad formats, so this guard fires for missing/empty price inputs that reach it as null. The library requires a price to build the publish form.","triggerScenarios":"Calling normalizePublishArgs (via the data handler) with kwargs.price === null or undefined — e.g. publishing without the price argument or with the price key omitted from kwargs.","commonSituations":"CLI invocations missing the price flag, JSON configs where the price key was renamed or dropped, or upstream optional-chaining yielding undefined that is passed straight through.","solutions":["Always pass a price: publish({ price: '19.90', ... })","Add a required-field check on args before invoking and print a usage hint","Fix upstream code that drops the price key (wrong destructure or renamed field)"],"exampleFix":"// before\nawait publish({ title: 'Book', description: 'good' }); // price missing\n// after\nawait publish({ title: 'Book', description: 'good', price: '19.90' });","handlingStrategy":"validation","validationCode":"if (kwargs.price == null || kwargs.price === '') {\n  throw new Error('xianyu publish requires a non-empty price');\n}","typeGuard":"function hasPrice(args) {\n  return args != null && args.price != null && String(args.price).trim() !== '';\n}","tryCatchPattern":"try {\n  await publish(kwargs);\n} catch (e) {\n  if (e instanceof ArgumentError && /price cannot be empty/.test(e.message)) {\n    console.error('Missing price; usage: publish --title T --description D --price 19.90');\n  } else throw e;\n}","preventionTips":["Make price a required CLI flag / schema field with a missing-field check","Validate the full args object (price, title, description) before invoking","Watch for upstream renames that silently drop the price key"],"tags":["validation","argument-error","missing-field","price"],"backgroundTag":"missing-required-field","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}