santifer/career-ops · error · Error
Unsupported image type
Error message
Unsupported image type: ${extname(inputPath) || '(no extension)'}. Supported: ${Object.keys(MIME_TYPES).join(', ')} What it means
convertImageToPdf() first detects the image's MIME type from its file extension using the MIME_TYPES table. When the extension is absent or unsupported (png/jpeg/gif/webp-style set), detection returns null and the conversion is refused before any file read or Chromium launch.
Solutions
- Convert the image to a supported format (e.g. with ImageMagick: `magick input.heic output.png`) and retry.
- Rename the file so it carries a supported extension if the bytes are already in that format.
- Check Object.keys(MIME_TYPES) in img-to-pdf.mjs for the exact supported extension list, and add the type there if it is genuinely renderable.
Example fix
// before
await convertImageToPdf('photo.heic', 'photo.pdf');
// after (pre-converted)
// $ magick photo.heic photo.png
await convertImageToPdf('photo.png', 'photo.pdf'); Defensive patterns
Strategy: validation
Validate before calling
import { extname } from 'node:path';
const SUPPORTED = ['.png', '.jpg', '.jpeg', '.gif', '.webp']; // match MIME_TYPES
if (!SUPPORTED.includes(extname(inputPath).toLowerCase())) {
throw new Error(`convert ${inputPath} to a supported format first`);
} Type guard
const isSupportedImage = (p) => ['.png', '.jpg', '.jpeg', '.gif', '.webp'].includes(extname(p).toLowerCase());
Try / catch
try {
await convertImageToPdf(input, output);
} catch (err) {
if (err.message.startsWith('Unsupported image type')) {
await exec(`magick ${input} ${input.replace(/\.\w+$/, '.png')}`);
return convertImageToPdf(input.replace(/\.\w+$/, '.png'), output);
}
throw err;
} Prevention
- Normalize all images to PNG/JPEG before PDF conversion pipelines.
- Ensure downloaded/converted files keep a proper extension.
- Check the MIME_TYPES table for the current supported list.
When it happens
Trigger: Calling convertImageToPdf() with a file whose extension is not in MIME_TYPES — e.g. .svg, .tiff, .bmp, .avif, .heic, or a file with no extension at all.
Common situations: Converting screenshots or exports in formats Chromium's <img> path wasn't configured for; extension-less temp files from downloads; camera RAW or HEIC phone photos.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Could not determine the rendered PDF page count
- Image failed to decode within 10s (unreadable or corrupt…
- (--strict-pages requested)
- 4dayweek: invalid URL
- 4dayweek: URL must use HTTPS
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/5c973f158623d05f.
Report an issue: GitHub.
Appendix: source
Thrown at img-to-pdf.mjs:107
console.log('');
console.log(' --force overwrite <output-path> if it already exists');
console.log('');
console.log('MVP scope: one image in, one PDF page out. Multi-image/multi-page is not supported.');
}
/**
* Render a single image file to a single-page PDF matching the image's own
* pixel dimensions (at 96 CSS px/inch), so the output is neither cropped
* nor padded with blank margins.
*
* @param {string} inputPath - Absolute path to the source image.
* @param {string} outputPath - Absolute path to write the PDF to.
* @returns {Promise<{outputPath: string, size: number, width: number, height: number}>}
*/
export async function convertImageToPdf(inputPath, outputPath) {
const mimeType = detectMimeType(inputPath);
if (!mimeType) {
throw new Error(`Unsupported image type: ${extname(inputPath) || '(no extension)'}. Supported: ${Object.keys(MIME_TYPES).join(', ')}`);
}
const buffer = await readFile(inputPath);
const base64 = buffer.toString('base64');
const html = `<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
* { margin: 0; padding: 0; }
html, body { margin: 0; padding: 0; }
img { display: block; }
</style>
</head>
<body>
<img id="career-ops-img" src="data:${mimeType};base64,${base64}">
</body>
</html>`;View on GitHub (pinned to aac998c7ed)