gchq/CyberChef · error · OperationError
Unsupported QR code format.
Error message
Unsupported QR code format.
What it means
Thrown by generateQrCode when the requested `format` (upper-cased) is not in ['SVG','EPS','PDF','PNG']. This is the entry-point validation before qr-image is invoked.
Source
Thrown at src/core/lib/QRCode.mjs:83
* Generates a QR code from the input string
*
* @param {string} input
* @param {string} format
* @param {number} moduleSize
* @param {number} margin
* @param {string} errorCorrection
* @returns {ArrayBuffer}
*/
export function generateQrCode(
input,
format,
moduleSize,
margin,
errorCorrection,
) {
const formats = ["SVG", "EPS", "PDF", "PNG"];
if (!formats.includes(format.toUpperCase())) {
throw new OperationError("Unsupported QR code format.");
}
let qrImage;
try {
qrImage = qr.imageSync(input, {
type: format,
size: moduleSize,
margin: margin,
// eslint-disable-next-line camelcase
ec_level: errorCorrection.charAt(0).toUpperCase(),
});
} catch (err) {
throw new OperationError(`Error generating QR code. (${err})`);
}
if (!qrImage) {
throw new OperationError("Error generating QR code.");
}View on GitHub (pinned to 4290ea7539)
Solutions
- Use one of: 'SVG', 'EPS', 'PDF', or 'PNG' (case-insensitive — the check upper-cases).
- Default the format argument when it may be undefined: `format || 'PNG'`.
Example fix
// before generateQrCode(text, 'JPEG', 4, 4, 'M'); // after generateQrCode(text, 'PNG', 4, 4, 'M');
Defensive patterns
Strategy: validation
Validate before calling
const QR_FORMATS = new Set(['SVG','EPS','PDF','PNG']);
const fmt = String(format ?? '').toUpperCase();
if (!QR_FORMATS.has(fmt)) throw new Error(`Unsupported QR format '${format}'`);
generateQrCode(input, fmt, moduleSize, margin, errorCorrection); Type guard
function isQrFormat(f) {
return ['SVG','EPS','PDF','PNG'].includes(String(f).toUpperCase());
} Try / catch
try {
return generateQrCode(input, format, moduleSize, margin, errorCorrection);
} catch (e) {
if (e instanceof OperationError && /Unsupported QR code format/.test(e.message)) {
// default to PNG and retry
}
throw e;
} Prevention
- Whitelist the format against SVG/EPS/PDF/PNG at the call site.
- Default format to 'PNG' when it may be missing.
- Pass the short code, not a MIME type.
When it happens
Trigger: Calling generateQrCode with a format like 'JPEG', 'GIF', 'BMP', '' (empty uppercases to ''), or undefined (String(undefined).toUpperCase() = 'UNDEFINED').
Common situations: UI dropdown value changed or unset; passing a MIME type instead of the short code; typo in format name; stale recipe referencing a removed format.
Related errors
- Error opening image. (${err})
- Could not read a QR code from the image.
- Error generating QR code. (${err})
- Error generating QR code.
- Unknown padding type: ${padding}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/22b398e4de063bc7.
Report an issue: GitHub.