jackwener/OpenCLI · error · CommandExecutionError
WeChat image upload returned a malformed editor image payloa
Error message
WeChat image upload returned a malformed editor image payload.
What it means
Thrown by readCdnImageKeys when the in-page script that collects existing CDN image URLs (data-src/src attributes matching mmbiz or qpic.cn) from the article editor body does not return an array. The library expects evaluate() to yield an array of strings; anything else means the editor DOM or the evaluate bridge behaved unexpectedly.
Source
Thrown at clis/weixin/create-draft.js:108
editor.focus();
if (editor.querySelector('[contenteditable="false"]')) editor.innerHTML = '';
document.execCommand('selectAll', false, null);
document.execCommand('insertText', false, ${JSON.stringify(text)});
editor.dispatchEvent(new InputEvent('input', { bubbles: true }));
return { ok: true };
})()`);
}
async function readCdnImageKeys(page) {
const keys = await evaluate(page, `(() => {
var editor = document.querySelector('#ueditor_0');
if (!editor) return [];
return Array.from(editor.querySelectorAll('img')).map(function(img) {
return img.getAttribute('data-src') || img.getAttribute('src') || '';
}).filter(function(src) { return /(?:mmbiz|qpic\\.cn)/i.test(src); });
})()`);
if (!Array.isArray(keys)) {
throw new CommandExecutionError('WeChat image upload returned a malformed editor image payload.');
}
return keys.map(String);
}
async function injectImageFile(page, image) {
if (typeof page.setFileInput === 'function') {
try {
await page.setFileInput([image.absPath], IMAGE_FILE_INPUT_SELECTOR);
return;
} catch (error) {
if (!isRecoverableFileInputError(error)) {
const message = error instanceof Error ? error.message : String(error);
throw new CommandExecutionError(`WeChat image upload failed: ${message}`);
}
}
}
const base64 = fs.readFileSync(image.absPath).toString('base64');View on GitHub (pinned to 49907e53dc)
Solutions
- Confirm the script is running on the actual WeChat article editor page (textarea#title present) before calling readCdnImageKeys.
- Check for a WeChat editor DOM update and update the editor content selector used by the library.
- Retry the operation; transient page states can make the evaluate result undefined.
- Log the raw evaluate result to see what shape came back and adjust parsing accordingly.
Example fix
// before
const keys = await evaluate(page, `...`);
if (!Array.isArray(keys)) {
throw new CommandExecutionError('WeChat image upload returned a malformed editor image payload.');
}
// after
const raw = await evaluate(page, `...`);
const keys = Array.isArray(raw) ? raw : (raw && Array.isArray(raw.keys) ? raw.keys : []);
if (!Array.isArray(raw)) console.warn('editor image payload malformed, treating as empty:', raw); Defensive patterns
Strategy: validation
Validate before calling
await page.wait(2);
const editorReady = await evaluate(page, '!!document.querySelector("textarea#title") && !!document.querySelector(".edui-body-container, #edui1_contentplaceholder, [contenteditable]")');
if (editorReady !== true) throw new Error('editor not ready for image key read'); Type guard
function isStringArray(v) { return Array.isArray(v) && v.every(x => typeof x === 'string'); } Try / catch
try {
await createDraftCommand(opts);
} catch (e) {
if (/malformed editor image payload/i.test(e.message)) {
return createDraftCommand(opts); // editor DOM may have been momentarily unavailable
}
throw e;
} Prevention
- Always run the command against a fully loaded editor page.
- Retry once on this error before investigating — it is often transient.
- Pin/monitor WeChat editor DOM changes that affect image attributes.
- Log raw evaluate results when debugging selector drift.
When it happens
Trigger: The evaluate call returns null/undefined because the editor container selector no longer matches, the page navigated away mid-operation, the in-page script threw and the evaluate bridge returned a non-array error shape, or the editor markup changed in a WeChat front-end update.
Common situations: WeChat updated the editor DOM classes/ids; the command ran against a page that is not the article editor; the session degraded so the editor content area is missing; evaluate serialization differences in the automation driver.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- LinkedIn people search returned malformed extraction payload
- Could not open WeChat image upload: ${opened?.reason || 'unk
- WeChat save-draft button was not found.
- Not a git repository
- Working tree not clean: ${status}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d6b05c67b02c6eeb.
Report an issue: GitHub.