{"record":{"id":"e7602598c9887fb9","repo":"jackwener/OpenCLI","slug":"xianyu-image-upload-failed-err-message-err","errorCode":null,"errorMessage":"Xianyu image upload failed: ${err?.message || err}","messagePattern":"Xianyu image upload failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/publish.js","lineNumber":430,"sourceCode":"            const missing = Array.isArray(fillResult?.missing) ? fillResult.missing.join(', ') : 'unknown';\n            throw new CommandExecutionError(`Xianyu publish form fill failed; missing fields: ${missing}`);\n        }\n        await page.wait(1);\n\n        // 5. 上传图片（如果有）\n        if (data.images.length > 0) {\n            if (!page.setFileInput) {\n                throw new CommandExecutionError('Xianyu publish requires Browser Bridge file upload support', 'Use a browser mode that supports setFileInput.');\n            }\n            const fileInput = await page.evaluate(buildFindFileInputSelectorEvaluate());\n            if (!fileInput?.ok) {\n                throw new CommandExecutionError(`Xianyu image upload input was not found: ${fileInput?.reason || 'unknown-reason'}`);\n            }\n            try {\n                await page.setFileInput(data.images, fileInput.selector || 'input[type=\"file\"]');\n                await page.wait(3); // 等待图片上传处理\n            } catch (err) {\n                throw new CommandExecutionError(`Xianyu image upload failed: ${err?.message || err}`);\n            }\n        }\n\n        // 6. 点击发布按钮\n        const submitResult = await page.evaluate(buildSubmitEvaluate());\n        if (!submitResult?.ok) {\n            throw new CommandExecutionError(`Xianyu publish submit failed: ${submitResult?.reason || 'unknown-reason'}`);\n        }\n\n        // 7. 等待发布结果（最多 15 秒轮询）\n        await page.wait(2);\n        let itemId = '';\n        let finalUrl = await getCurrentPageUrl(page);\n        let failReason = '';\n\n        for (let i = 0; i < 10; i++) {\n            await page.wait(1.5);\n            const result = await page.evaluate(buildDetectSuccessEvaluate());","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/publish.js#L412-L448","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Verify every path in data.images exists and is readable by the browser process (absolute paths are safest).","Check the wrapped err.message for the underlying cause (e.g. ENOENT vs browser-side error) and fix accordingly.","Confirm the images are supported formats (jpg/png) and sizes accepted by goofish, then retry."],"exampleFix":"// before\nawait page.setFileInput(data.images, fileInput.selector || 'input[type=\"file\"]');\n// after: validate paths exist before uploading\nimport { existsSync } from 'node:fs';\nconst files = data.images.filter((p) => existsSync(p));\nawait page.setFileInput(files, fileInput.selector || 'input[type=\"file\"]');","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'node:fs';\nconst bad = images.filter((p) => !existsSync(p) || !statSync(p).size);\nif (bad.length) throw new Error(`Image files missing or empty: ${bad.join(', ')}`);","typeGuard":"const isUsableImagePath = (p) => typeof p === 'string' && p.length > 0 && existsSync(p) && /\\.(jpe?g|png|webp)$/i.test(p);","tryCatchPattern":"try {\n  await publish({ ...data, images });\n} catch (e) {\n  if (String(e.message).includes('image upload failed')) {\n    console.error('Underlying cause:', e.message); // includes wrapped err.message\n    // fix paths/formats then retry\n  }\n  throw e;\n}","preventionTips":["Always pass absolute, existing image paths accessible to the browser process.","Pre-validate formats (jpg/png/webp) and sizes against goofish limits.","Run the CLI's validateImagePaths helper on image lists before publishing."],"tags":["file-upload","filesystem","browser-automation","xianyu"],"backgroundTag":"file-upload-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}