jackwener/OpenCLI · error · ArgumentError

Unsupported image format "${ext}". Supported: jpg, png, gif,

Error message

Unsupported image format "${ext}". Supported: jpg, png, gif, webp

What it means

Each supplied image path must have an extension in SUPPORTED_EXTENSIONS (jpg, png, gif, webp, compared case-insensitively after path.resolve). Anything else raises an ArgumentError naming the bad extension.

Source

Thrown at clis/weibo/publish.js:61

function validateText(text) {
    const t = String(text ?? '').trim();
    if (!t) throw new ArgumentError('weibo publish text cannot be empty');
    if (t.length > 2000) throw new ArgumentError('weibo publish text exceeds 2000 characters');
    return t;
}

function validateImagePaths(raw) {
    if (!raw) return [];
    const paths = raw.split(',').map(s => s.trim()).filter(Boolean);
    if (paths.length > MAX_IMAGES) {
        throw new ArgumentError(`Too many images: ${paths.length} (max ${MAX_IMAGES})`);
    }
    return paths.map(p => {
        const absPath = path.resolve(p);
        const ext = path.extname(absPath).toLowerCase();
        if (!SUPPORTED_EXTENSIONS.has(ext)) {
            throw new ArgumentError(`Unsupported image format "${ext}". Supported: jpg, png, gif, webp`);
        }
        const stat = fs.statSync(absPath, { throwIfNoEntry: false });
        if (!stat || !stat.isFile()) {
            throw new ArgumentError(`Not a valid file: ${absPath}`);
        }
        return absPath;
    });
}

cli({
    site: 'weibo',
    name: 'publish',
    access: 'write',
    description: 'Publish a new Weibo post immediately',
    domain: 'weibo.com',
    strategy: Strategy.UI,
    browser: true,
    args: [

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert the image to jpg or png (e.g. `sips -s format jpeg in.heic --out out.jpg` or ImageMagick `convert`)
  2. Rename/move files so they carry a supported extension if the content is already jpg/png/gif/webp
  3. Filter the list to supported extensions before invoking

Example fix

// before
weibo publish --text "hi" --images photo.heic
// after
magick photo.heic photo.jpg
weibo publish --text "hi" --images photo.jpg
Defensive patterns

Strategy: validation

Validate before calling

const OK = new Set(['.jpg', '.png', '.gif', '.webp']);
for (const p of paths) {
  const ext = require('path').extname(p).toLowerCase();
  if (!OK.has(ext)) throw new Error(`unsupported: ${ext} (${p})`);
}

Type guard

function hasSupportedExt(p) {
  return ['.jpg', '.png', '.gif', '.webp']
    .includes(require('path').extname(p).toLowerCase());
}

Try / catch

try {
  await cli.run(['weibo', 'publish', '--text', text, '--images', images]);
} catch (err) {
  if (/Unsupported image format/.test(err.message)) {
    console.error('Convert to jpg/png/gif/webp first');
  } else throw err;
}

Prevention

When it happens

Trigger: Passing --images entries ending in .jpeg, .bmp, .heic, .avif, or files with no extension at all.

Common situations: iPhone HEIC photos; screenshots saved as .jpeg or .tiff; temp files without extensions; uppercase extensions are fine (lowercased) but uncommon formats are not.

Related errors


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