{"record":{"id":"36e65f81796b9103","repo":"jackwener/OpenCLI","slug":"weixin-create-draft-cover-image-cannot-be-empty","errorCode":null,"errorMessage":"weixin create-draft cover-image cannot be empty","messagePattern":"weixin create-draft cover-image cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weixin/create-draft.js","lineNumber":35,"sourceCode":"function unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && typeof payload.session === 'string' && Object.hasOwn(payload, 'data')) {\n        return payload.data;\n    }\n    return payload;\n}\n\nasync function evaluate(page, script) {\n    return unwrapEvaluateResult(await page.evaluate(script));\n}\n\nfunction isRecoverableFileInputError(error) {\n    const message = error instanceof Error ? error.message : String(error);\n    return /unknown action|not supported|not[-\\s]?allowed|notallowederror/i.test(message);\n}\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","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weixin/create-draft.js#L17-L53","documentation":"resolveCoverImage requires a non-empty cover image path for the weixin create-draft command; an empty/whitespace/undefined value throws this ArgumentError before any filesystem access.","triggerScenarios":"Calling create-draft without cover-image, with an empty string, or with a value that is only whitespace (or null/undefined coerced to '').","commonSituations":"Missing CLI flag; config file where the cover-image key is blank; programmatically passing an unset variable.","solutions":["Pass a valid cover-image path to create-draft.","Check your config file/CLI flags for a blank or missing cover-image value.","Default to a bundled template cover image if your workflow allows it."],"exampleFix":"// before\nawait weixinCreateDraft({ title, content, coverImage: process.env.COVER });\n// after\nif (!process.env.COVER) throw new Error('Set COVER to a JPEG/PNG/GIF/WebP path');\nawait weixinCreateDraft({ title, content, coverImage: process.env.COVER });","handlingStrategy":"validation","validationCode":"const cover = process.argv[coverIdx];\nif (typeof cover !== 'string' || !cover.trim()) {\n  throw new Error('cover-image is required');\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await createDraft({ title, content, coverImage });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {\n    console.error('Provide --cover-image <path>');\n  } else throw err;\n}","preventionTips":["Validate CLI args/config before invoking the command","Provide a default cover image in templates","Trim inputs and reject whitespace-only values","Document the required cover-image flag"],"tags":["weixin","argument-error","validation","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}