jackwener/OpenCLI · error · ArgumentError

xianyu publish price cannot be empty

Error message

xianyu publish price cannot be empty

What it means

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.

Source

Thrown at clis/xianyu/publish.js:81

    }
    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 });
        if (!stat || !stat.isFile()) {
            throw new ArgumentError(`Not a valid image file: ${absPath}`);
        }
        return absPath;
    });
}

function normalizePublishArgs(kwargs) {
    const price = parsePositivePrice(kwargs.price, 'price');
    if (price == null) {
        throw new ArgumentError('xianyu publish price cannot be empty');
    }
    const normalized = {};
    normalized.title = requireText(kwargs.title, 'title');
    normalized.description = requireText(kwargs.description, 'description');
    normalized.price = price;
    normalized.condition = validateCondition(kwargs.condition);
    normalized.category = requireText(kwargs.category, 'category');
    normalized.original_price = parsePositivePrice(kwargs.original_price, 'original_price');
    normalized.location = kwargs.location ? requireText(kwargs.location, 'location') : '';
    normalized.images = validateImagePaths(kwargs.images);
    return normalized;
}

// ===== 表单填充 evaluate scripts =====

function buildFillFormEvaluate(data) {
    return `
    (() => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Always pass a price: publish({ price: '19.90', ... })
  2. Add a required-field check on args before invoking and print a usage hint
  3. Fix upstream code that drops the price key (wrong destructure or renamed field)

Example fix

// before
await publish({ title: 'Book', description: 'good' }); // price missing
// after
await publish({ title: 'Book', description: 'good', price: '19.90' });
Defensive patterns

Strategy: validation

Validate before calling

if (kwargs.price == null || kwargs.price === '') {
  throw new Error('xianyu publish requires a non-empty price');
}

Type guard

function hasPrice(args) {
  return args != null && args.price != null && String(args.price).trim() !== '';
}

Try / catch

try {
  await publish(kwargs);
} catch (e) {
  if (e instanceof ArgumentError && /price cannot be empty/.test(e.message)) {
    console.error('Missing price; usage: publish --title T --description D --price 19.90');
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/aa862ef9645c110d. Report an issue: GitHub.