jackwener/OpenCLI · error · ArgumentError

weixin create-draft cover-image cannot be empty

Error message

weixin create-draft cover-image cannot be empty

What it means

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.

Source

Thrown at clis/weixin/create-draft.js:35

function unwrapEvaluateResult(payload) {
    if (payload && typeof payload === 'object' && typeof payload.session === 'string' && Object.hasOwn(payload, 'data')) {
        return payload.data;
    }
    return payload;
}

async function evaluate(page, script) {
    return unwrapEvaluateResult(await page.evaluate(script));
}

function isRecoverableFileInputError(error) {
    const message = error instanceof Error ? error.message : String(error);
    return /unknown action|not supported|not[-\s]?allowed|notallowederror/i.test(message);
}

function resolveCoverImage(rawPath) {
    const value = String(rawPath ?? '').trim();
    if (!value) throw new ArgumentError('weixin create-draft cover-image cannot be empty');
    const absPath = path.resolve(value);
    let stat;
    try {
        stat = fs.statSync(absPath);
    } catch {
        throw new ArgumentError(`weixin create-draft cover-image does not exist: ${absPath}`);
    }
    if (!stat.isFile()) {
        throw new ArgumentError(`weixin create-draft cover-image is not a file: ${absPath}`);
    }
    const extension = path.extname(absPath).toLowerCase();
    const mimeType = IMAGE_MIME_TYPES.get(extension);
    if (!mimeType) {
        throw new ArgumentError('weixin create-draft cover-image must be JPEG, PNG, GIF, or WebP');
    }
    return { absPath, fileName: path.basename(absPath), mimeType };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a valid cover-image path to create-draft.
  2. Check your config file/CLI flags for a blank or missing cover-image value.
  3. Default to a bundled template cover image if your workflow allows it.

Example fix

// before
await weixinCreateDraft({ title, content, coverImage: process.env.COVER });
// after
if (!process.env.COVER) throw new Error('Set COVER to a JPEG/PNG/GIF/WebP path');
await weixinCreateDraft({ title, content, coverImage: process.env.COVER });
Defensive patterns

Strategy: validation

Validate before calling

const cover = process.argv[coverIdx];
if (typeof cover !== 'string' || !cover.trim()) {
  throw new Error('cover-image is required');
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await createDraft({ title, content, coverImage });
} catch (err) {
  if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {
    console.error('Provide --cover-image <path>');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling create-draft without cover-image, with an empty string, or with a value that is only whitespace (or null/undefined coerced to '').

Common situations: Missing CLI flag; config file where the cover-image key is blank; programmatically passing an unset variable.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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