gchq/CyberChef · error · OperationError

Error generating QR code.

Error message

Error generating QR code.

What it means

Thrown by generateQrCode when `qr.imageSync` returns a falsy value (null/undefined/empty) without throwing — qr-image signalled failure silently. Treated as a generation failure distinct from the thrown-exception case.

Source

Thrown at src/core/lib/QRCode.mjs:100

    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.");
    }

    switch (format) {
        case "SVG":
        case "EPS":
        case "PDF":
            return Utils.strToArrayBuffer(qrImage);
        case "PNG":
            return qrImage.buffer.slice(qrImage.byteOffset, qrImage.byteLength + qrImage.byteOffset);
        default:
            throw new OperationError("Unsupported QR code format.");
    }
}

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure input is a non-empty string.
  2. Pass the format in the case qr-image expects (the call forwards `type: format` verbatim — see also error 134).
  3. Pin a known-good qr-image version.

Example fix

// before
generateQrCode('', 'PNG', 4, 4, 'M');
// after
generateQrCode('https://example.com', 'PNG', 4, 4, 'M');
Defensive patterns

Strategy: validation

Validate before calling

if (typeof input !== 'string' || input.length === 0) {
  throw new Error('QR input must be a non-empty string');
}

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }

Try / catch

try {
  return generateQrCode(input, format, moduleSize, margin, errorCorrection);
} catch (e) {
  if (e instanceof OperationError && /^Error generating QR code\.$/.test(e.message)) {
    // qr-image returned nothing — try SVG format or different EC
  }
  throw e;
}

Prevention

When it happens

Trigger: An input/option combination that qr-image handles by returning nothing rather than throwing — e.g. empty string input, or an option set the installed qr-image version refuses.

Common situations: Empty input string; qr-image version regression; mismatch between the `type` code passed and what qr-image expects (case sensitivity of `type`).

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/d89e442f2b5275bd. Report an issue: GitHub.