jackwener/OpenCLI · error · CommandExecutionError

Xianyu category selection failed

Error message

Xianyu category selection failed: ${categoryResult?.reason || 'unknown-reason'}

What it means

The publish flow calls buildSelectCategoryEvaluate(data.category) in the page; if the result is falsy or lacks ok, it throws CommandExecutionError including the in-page reason, or 'unknown-reason' when none is provided. It means the category could not be selected on the goofish publish form.

Solutions

  1. Use an exact category name supported by the form (read the in-page reason for specifics)
  2. Increase the wait before category selection so the dialog/menu is rendered
  3. Omit an unmatchable custom category and fall back to the site default
  4. Update buildSelectCategoryEvaluate selectors if goofish changed its DOM

Example fix

// before
await publish({ category: '数码/二手手机/苹果 iPhone 99', ... }); // nonexistent leaf
// after
await publish({ category: '手机', ... }); // valid, supported category
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_CATEGORIES = ['手机', '数码', '服装', '家居']; // from your catalog
if (!SUPPORTED_CATEGORIES.includes(data.category)) {
  throw new Error(`Unsupported category: ${data.category}`);
}

Type guard

function isValidCategory(c) {
  return typeof c === 'string' && c.trim().length > 0;
}

Try / catch

try {
  await publish(data);
} catch (e) {
  if (e instanceof CommandExecutionError && /category selection failed/.test(e.message)) {
    const reason = e.message.match(/failed: (.+)$/)?.[1];
    console.error(`Category "${data.category}" rejected (${reason}); retrying without category`);
    await publish({ ...data, category: undefined });
  } else throw e;
}

Prevention

When it happens

Trigger: data.category matching no available option in the form's category tree, or the category dialog/menu failing to open or render (categoryResult.ok false/undefined with a reason string).

Common situations: Category name at the wrong tree level or with a typo, goofish renaming categories, the category menu rendering slower than the evaluate runs, or form layout changes breaking in-page selection logic.

Related errors


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

Appendix: source

Thrown at clis/xianyu/publish.js:405

    func: async (page, kwargs) => {
        const data = normalizePublishArgs(kwargs);
        // 1. 导航到发布页
        await page.goto(buildPublishUrl());
        await page.wait(3);

        // 2. 检查登录状态
        const initState = await page.evaluate(buildExtractPageStateEvaluate());
        if (initState?.requiresAuth) {
            throw new AuthRequiredError('www.goofish.com', '发布闲鱼需要先登录,请在 Chrome 中打开 goofish.com 并完成登录');
        }
        if (!initState?.hasPublishForm) {
            throw new CommandExecutionError('Xianyu publish form was not detected', 'Confirm goofish.com is logged in and the publish page finished loading.');
        }

        // 3. 选择分类(先于其他字段,因为分类可能影响表单结构)
        const categoryResult = await page.evaluate(buildSelectCategoryEvaluate(data.category));
        if (!categoryResult?.ok) {
            throw new CommandExecutionError(`Xianyu category selection failed: ${categoryResult?.reason || 'unknown-reason'}`);
        }
        await page.wait(1.5);

        // 4. 填充表单
        const fillResult = await page.evaluate(buildFillFormEvaluate(data));
        if (!fillResult?.ok) {
            const missing = Array.isArray(fillResult?.missing) ? fillResult.missing.join(', ') : 'unknown';
            throw new CommandExecutionError(`Xianyu publish form fill failed; missing fields: ${missing}`);
        }
        await page.wait(1);

        // 5. 上传图片(如果有)
        if (data.images.length > 0) {
            if (!page.setFileInput) {
                throw new CommandExecutionError('Xianyu publish requires Browser Bridge file upload support', 'Use a browser mode that supports setFileInput.');
            }
            const fileInput = await page.evaluate(buildFindFileInputSelectorEvaluate());
            if (!fileInput?.ok) {

View on GitHub (pinned to 49907e53dc)