abpframework/abp · error · Error

Too long data

Error message

Too long data

What it means

Thrown by the internal _getTypeNumber auto-detection routine. When typeNumber is 0 (auto), the library walks QRCodeLimitLength entries to find the smallest QR type (1..40) whose capacity covers _getUTF8Length(sText) at the chosen errorCorrectLevel. If even type 40 (the largest) at the given correction level is too small, nType overshoots the table and it throws 'Too long data'. This is a hard physical limit of the QR spec, not a bug.

Source

Thrown at npm/packs/qrcode/src/qrcode.js:499

					nLimit = QRCodeLimitLength[i][1];
					break;
				case QRErrorCorrectLevel.Q :
					nLimit = QRCodeLimitLength[i][2];
					break;
				case QRErrorCorrectLevel.H :
					nLimit = QRCodeLimitLength[i][3];
					break;
			}
			
			if (length <= nLimit) {
				break;
			} else {
				nType++;
			}
		}
		
		if (nType > QRCodeLimitLength.length) {
			throw new Error("Too long data");
		}
		
		return nType;
	}

	function _getUTF8Length(sText) {
		var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
		return replacedText.length + (replacedText.length != sText ? 3 : 0);
	}
	
	/**
	 * @class QRCode
	 * @constructor
	 * @example 
	 * new QRCode(document.getElementById("test"), "http://jindo.dev.naver.com/collie");
	 *
	 * @example
	 * var oQRCode = new QRCode("test", {

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Lower correctLevel to L (max capacity: ~2953 bytes at type 40).
  2. Reduce the payload: shorten URLs (use a shortener), drop redundant query params, or host the data and encode only a link.
  3. Split the data across multiple QR codes if it must be self-contained.
  4. Switch to a binary/byte encoding path that avoids UTF-8 multi-byte expansion for non-ASCII content.

Example fix

// before
var qr = new QRCode(el, { text: hugeBase64Blob,
  correctLevel: QRCode.CorrectLevel.H }); // 'Too long data'

// after
var qr = new QRCode(el, { text: 'https://sho.rt/' + shortId,
  correctLevel: QRCode.CorrectLevel.L });
Defensive patterns

Strategy: validation

Validate before calling

function fitsAnyType(text, errorCorrectLevel) {
  var len = _getUTF8Length(text);
  // QRCodeLimitLength[39][levelIndex] is the type-40 max
  var idx = errorCorrectLevel; // map L=0,M=1,Q=2,H=3 per package
  return len <= QRCodeLimitLength[39][idx];
}

Type guard

null

Try / catch

try { new QRCode(el, { text: data, correctLevel: QRCode.CorrectLevel.L }); } catch (e) { if (e.message === 'Too long data') { /* shorten data or split */ } else throw e; }

Prevention

When it happens

Trigger: Constructing QRCode with typeNumber 0 (or omitted) for a string whose UTF-8 length exceeds QRCodeLimitLength[39] (the type-40 row) at the selected correctLevel. The throw happens during _getTypeNumber, called from the constructor/addData path.

Common situations: Encoding a very long URL, base64 blob, or multi-line text at correctLevel H (the most restrictive); using correctLevel H by default without realizing it halves capacity; feeding binary/base64 that encodeURI expands.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/e4f2fce7fea1ac26. Report an issue: GitHub.