{"record":{"id":"22b398e4de063bc7","repo":"gchq/CyberChef","slug":"unsupported-qr-code-format","errorCode":null,"errorMessage":"Unsupported QR code format.","messagePattern":"Unsupported QR code format\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/QRCode.mjs","lineNumber":83,"sourceCode":" * Generates a QR code from the input string\n *\n * @param {string} input\n * @param {string} format\n * @param {number} moduleSize\n * @param {number} margin\n * @param {string} errorCorrection\n * @returns {ArrayBuffer}\n */\nexport function generateQrCode(\n    input,\n    format,\n    moduleSize,\n    margin,\n    errorCorrection,\n) {\n    const formats = [\"SVG\", \"EPS\", \"PDF\", \"PNG\"];\n    if (!formats.includes(format.toUpperCase())) {\n        throw new OperationError(\"Unsupported QR code format.\");\n    }\n\n    let qrImage;\n    try {\n        qrImage = qr.imageSync(input, {\n            type: format,\n            size: moduleSize,\n            margin: margin,\n            // eslint-disable-next-line camelcase\n            ec_level: errorCorrection.charAt(0).toUpperCase(),\n        });\n    } catch (err) {\n        throw new OperationError(`Error generating QR code. (${err})`);\n    }\n\n    if (!qrImage) {\n        throw new OperationError(\"Error generating QR code.\");\n    }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/QRCode.mjs#L65-L101","documentation":"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.","triggerScenarios":"Calling generateQrCode with a format like 'JPEG', 'GIF', 'BMP', '' (empty uppercases to ''), or undefined (String(undefined).toUpperCase() = 'UNDEFINED').","commonSituations":"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.","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'`."],"exampleFix":"// before\ngenerateQrCode(text, 'JPEG', 4, 4, 'M');\n// after\ngenerateQrCode(text, 'PNG', 4, 4, 'M');","handlingStrategy":"validation","validationCode":"const QR_FORMATS = new Set(['SVG','EPS','PDF','PNG']);\nconst fmt = String(format ?? '').toUpperCase();\nif (!QR_FORMATS.has(fmt)) throw new Error(`Unsupported QR format '${format}'`);\ngenerateQrCode(input, fmt, moduleSize, margin, errorCorrection);","typeGuard":"function isQrFormat(f) {\n  return ['SVG','EPS','PDF','PNG'].includes(String(f).toUpperCase());\n}","tryCatchPattern":"try {\n  return generateQrCode(input, format, moduleSize, margin, errorCorrection);\n} catch (e) {\n  if (e instanceof OperationError && /Unsupported QR code format/.test(e.message)) {\n    // default to PNG and retry\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["qrcode","format","validation","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}