{"record":{"id":"a999dda89c747d70","repo":"jackwener/OpenCLI","slug":"weixin-create-draft-cover-image-must-be-jpeg-png","errorCode":null,"errorMessage":"weixin create-draft cover-image must be JPEG, PNG, GIF, or WebP","messagePattern":"weixin create-draft cover-image must be JPEG, PNG, GIF, or WebP","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weixin/create-draft.js","lineNumber":49,"sourceCode":"}\n\nfunction resolveCoverImage(rawPath) {\n    const value = String(rawPath ?? '').trim();\n    if (!value) throw new ArgumentError('weixin create-draft cover-image cannot be empty');\n    const absPath = path.resolve(value);\n    let stat;\n    try {\n        stat = fs.statSync(absPath);\n    } catch {\n        throw new ArgumentError(`weixin create-draft cover-image does not exist: ${absPath}`);\n    }\n    if (!stat.isFile()) {\n        throw new ArgumentError(`weixin create-draft cover-image is not a file: ${absPath}`);\n    }\n    const extension = path.extname(absPath).toLowerCase();\n    const mimeType = IMAGE_MIME_TYPES.get(extension);\n    if (!mimeType) {\n        throw new ArgumentError('weixin create-draft cover-image must be JPEG, PNG, GIF, or WebP');\n    }\n    return { absPath, fileName: path.basename(absPath), mimeType };\n}\n\nasync function navigateToEditor(page) {\n    await page.goto(WEIXIN_HOME);\n    await page.wait(3);\n    const token = await evaluate(page, `(window.location.href.match(/token=(\\\\d+)/)||[])[1]`);\n    if (!token) {\n        throw new AuthRequiredError(WEIXIN_DOMAIN, 'Please log in to the WeChat Official Account platform and retry.');\n    }\n    await page.goto(`https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit_v2&action=edit&isNew=1&type=77&token=${token}&lang=zh_CN`);\n    await page.wait(4);\n    const hasTitle = await evaluate(page, '!!document.querySelector(\"textarea#title\")');\n    if (hasTitle !== true) {\n        throw new CommandExecutionError('WeChat article editor did not load. The session may have expired.');\n    }\n}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/create-draft.js#L31-L67","documentation":"The path is an existing regular file but its extension is not in IMAGE_MIME_TYPES, so the library cannot determine a supported MIME type. WeChat draft cover images must be JPEG, PNG, GIF, or WebP.","triggerScenarios":"Passing a cover image with an unsupported extension (.bmp, .tiff, .avif, .heic) or an odd/uppercase-less mismatch such as .jpeg-less variants the map lacks; also a non-image file renamed to .png is caught only if the extension is unknown.","commonSituations":"Modern camera HEIC files; screenshots saved as BMP/TIFF; files with no extension; case-sensitive extension lookup on '.PNG' if the map is lowercase-only and extname case differs (here extname is lowercased, so truly exotic extensions only).","solutions":["Convert the image to JPEG, PNG, GIF, or WebP (e.g. with sharp/ImageMagick).","Rename the file so it has a supported extension if it actually is one of those formats.","Check the IMAGE_MIME_TYPES map if you maintain the CLI and add needed types deliberately."],"exampleFix":"// before\ncoverImage: 'photo.heic'\n// after\n// magick photo.heic photo.jpg\ncoverImage: 'photo.jpg'","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['.jpg','.jpeg','.png','.gif','.webp'];\nconst ext = path.extname(coverImage).toLowerCase();\nif (!SUPPORTED.includes(ext)) throw new Error(`unsupported cover format: ${ext}`);","typeGuard":"function isSupportedImage(p) {\n  return ['.jpg','.jpeg','.png','.gif','.webp'].includes(path.extname(p).toLowerCase());\n}","tryCatchPattern":"try {\n  await createDraft({ coverImage });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('JPEG, PNG, GIF')) {\n    console.error('Convert the image to JPEG/PNG/GIF/WebP first');\n  } else throw err;\n}","preventionTips":["Normalize/convert images to supported formats in a pre-step","Strip HEIC/BMP/TIFF inputs at ingestion","Keep extensions lowercase and consistent","Optionally verify MIME via magic bytes, not just extension"],"tags":["weixin","argument-error","image-format","validation"],"backgroundTag":"unsupported-file-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}