jackwener/OpenCLI · error · CommandExecutionError

Xianyu image upload failed: ${err?.message || err}

Error message

Xianyu image upload failed: ${err?.message || err}

What it means

The file input was found, but calling page.setFileInput(data.images, selector) to attach the local image files failed. The original error is rethrown as a CommandExecutionError wrapping err.message. This is the actual upload/attachment step failing, not the input lookup.

Source

Thrown at clis/xianyu/publish.js:430

            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) {
                throw new CommandExecutionError(`Xianyu image upload input was not found: ${fileInput?.reason || 'unknown-reason'}`);
            }
            try {
                await page.setFileInput(data.images, fileInput.selector || 'input[type="file"]');
                await page.wait(3); // 等待图片上传处理
            } catch (err) {
                throw new CommandExecutionError(`Xianyu image upload failed: ${err?.message || err}`);
            }
        }

        // 6. 点击发布按钮
        const submitResult = await page.evaluate(buildSubmitEvaluate());
        if (!submitResult?.ok) {
            throw new CommandExecutionError(`Xianyu publish submit failed: ${submitResult?.reason || 'unknown-reason'}`);
        }

        // 7. 等待发布结果(最多 15 秒轮询)
        await page.wait(2);
        let itemId = '';
        let finalUrl = await getCurrentPageUrl(page);
        let failReason = '';

        for (let i = 0; i < 10; i++) {
            await page.wait(1.5);
            const result = await page.evaluate(buildDetectSuccessEvaluate());

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify every path in data.images exists and is readable by the browser process (absolute paths are safest).
  2. Check the wrapped err.message for the underlying cause (e.g. ENOENT vs browser-side error) and fix accordingly.
  3. Confirm the images are supported formats (jpg/png) and sizes accepted by goofish, then retry.

Example fix

// before
await page.setFileInput(data.images, fileInput.selector || 'input[type="file"]');
// after: validate paths exist before uploading
import { existsSync } from 'node:fs';
const files = data.images.filter((p) => existsSync(p));
await page.setFileInput(files, fileInput.selector || 'input[type="file"]');
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync, statSync } from 'node:fs';
const bad = images.filter((p) => !existsSync(p) || !statSync(p).size);
if (bad.length) throw new Error(`Image files missing or empty: ${bad.join(', ')}`);

Type guard

const isUsableImagePath = (p) => typeof p === 'string' && p.length > 0 && existsSync(p) && /\.(jpe?g|png|webp)$/i.test(p);

Try / catch

try {
  await publish({ ...data, images });
} catch (e) {
  if (String(e.message).includes('image upload failed')) {
    console.error('Underlying cause:', e.message); // includes wrapped err.message
    // fix paths/formats then retry
  }
  throw e;
}

Prevention

When it happens

Trigger: `xianyu publish` with images where page.setFileInput throws — nonexistent image file paths, unsupported file type, or the browser-side upload call rejecting for the given selector.

Common situations: Image paths that don't exist or aren't accessible to the browser process; images failing validateImagePaths upstream is bypassed by passing raw paths; browser rejecting non-image MIME types or files too large; transient renderer crash mid-upload.

Related errors


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