{"record":{"id":"44d65a18f53f510b","repo":"jackwener/OpenCLI","slug":"unsupported-image-format-ext-supported-jpg-44d65a","errorCode":null,"errorMessage":"Unsupported image format \"${ext}\". Supported: jpg, png, gif, webp","messagePattern":"Unsupported image format \"(.+?)\"\\. Supported: jpg, png, gif, webp","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/publish.js","lineNumber":61,"sourceCode":"\nfunction validateText(text) {\n    const t = String(text ?? '').trim();\n    if (!t) throw new ArgumentError('weibo publish text cannot be empty');\n    if (t.length > 2000) throw new ArgumentError('weibo publish text exceeds 2000 characters');\n    return t;\n}\n\nfunction validateImagePaths(raw) {\n    if (!raw) return [];\n    const paths = raw.split(',').map(s => s.trim()).filter(Boolean);\n    if (paths.length > MAX_IMAGES) {\n        throw new ArgumentError(`Too many images: ${paths.length} (max ${MAX_IMAGES})`);\n    }\n    return paths.map(p => {\n        const absPath = path.resolve(p);\n        const ext = path.extname(absPath).toLowerCase();\n        if (!SUPPORTED_EXTENSIONS.has(ext)) {\n            throw new ArgumentError(`Unsupported image format \"${ext}\". Supported: jpg, png, gif, webp`);\n        }\n        const stat = fs.statSync(absPath, { throwIfNoEntry: false });\n        if (!stat || !stat.isFile()) {\n            throw new ArgumentError(`Not a valid file: ${absPath}`);\n        }\n        return absPath;\n    });\n}\n\ncli({\n    site: 'weibo',\n    name: 'publish',\n    access: 'write',\n    description: 'Publish a new Weibo post immediately',\n    domain: 'weibo.com',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/publish.js#L43-L79","documentation":"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.","triggerScenarios":"Passing --images entries ending in .jpeg, .bmp, .heic, .avif, or files with no extension at all.","commonSituations":"iPhone HEIC photos; screenshots saved as .jpeg or .tiff; temp files without extensions; uppercase extensions are fine (lowercased) but uncommon formats are not.","solutions":["Convert the image to jpg or png (e.g. `sips -s format jpeg in.heic --out out.jpg` or ImageMagick `convert`)","Rename/move files so they carry a supported extension if the content is already jpg/png/gif/webp","Filter the list to supported extensions before invoking"],"exampleFix":"// before\nweibo publish --text \"hi\" --images photo.heic\n// after\nmagick photo.heic photo.jpg\nweibo publish --text \"hi\" --images photo.jpg","handlingStrategy":"validation","validationCode":"const OK = new Set(['.jpg', '.png', '.gif', '.webp']);\nfor (const p of paths) {\n  const ext = require('path').extname(p).toLowerCase();\n  if (!OK.has(ext)) throw new Error(`unsupported: ${ext} (${p})`);\n}","typeGuard":"function hasSupportedExt(p) {\n  return ['.jpg', '.png', '.gif', '.webp']\n    .includes(require('path').extname(p).toLowerCase());\n}","tryCatchPattern":"try {\n  await cli.run(['weibo', 'publish', '--text', text, '--images', images]);\n} catch (err) {\n  if (/Unsupported image format/.test(err.message)) {\n    console.error('Convert to jpg/png/gif/webp first');\n  } else throw err;\n}","preventionTips":["Convert HEIC/JPEG-variant/AVIF files to jpg or png first","Pre-filter lists with extension checks","Note .jpeg is NOT in the supported set — rename to .jpg"],"tags":["validation","argument-error","file-format"],"backgroundTag":"unsupported-file-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}