{"record":{"id":"e4f2fce7fea1ac26","repo":"abpframework/abp","slug":"too-long-data","errorCode":null,"errorMessage":"Too long data","messagePattern":"Too long data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/packs/qrcode/src/qrcode.js","lineNumber":499,"sourceCode":"\t\t\t\t\tnLimit = QRCodeLimitLength[i][1];\n\t\t\t\t\tbreak;\n\t\t\t\tcase QRErrorCorrectLevel.Q :\n\t\t\t\t\tnLimit = QRCodeLimitLength[i][2];\n\t\t\t\t\tbreak;\n\t\t\t\tcase QRErrorCorrectLevel.H :\n\t\t\t\t\tnLimit = QRCodeLimitLength[i][3];\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (length <= nLimit) {\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tnType++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (nType > QRCodeLimitLength.length) {\n\t\t\tthrow new Error(\"Too long data\");\n\t\t}\n\t\t\n\t\treturn nType;\n\t}\n\n\tfunction _getUTF8Length(sText) {\n\t\tvar replacedText = encodeURI(sText).toString().replace(/\\%[0-9a-fA-F]{2}/g, 'a');\n\t\treturn replacedText.length + (replacedText.length != sText ? 3 : 0);\n\t}\n\t\n\t/**\n\t * @class QRCode\n\t * @constructor\n\t * @example \n\t * new QRCode(document.getElementById(\"test\"), \"http://jindo.dev.naver.com/collie\");\n\t *\n\t * @example\n\t * var oQRCode = new QRCode(\"test\", {","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/npm/packs/qrcode/src/qrcode.js#L481-L517","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Lower correctLevel to L (max capacity: ~2953 bytes at type 40).","Reduce the payload: shorten URLs (use a shortener), drop redundant query params, or host the data and encode only a link.","Split the data across multiple QR codes if it must be self-contained.","Switch to a binary/byte encoding path that avoids UTF-8 multi-byte expansion for non-ASCII content."],"exampleFix":"// before\nvar qr = new QRCode(el, { text: hugeBase64Blob,\n  correctLevel: QRCode.CorrectLevel.H }); // 'Too long data'\n\n// after\nvar qr = new QRCode(el, { text: 'https://sho.rt/' + shortId,\n  correctLevel: QRCode.CorrectLevel.L });","handlingStrategy":"validation","validationCode":"function fitsAnyType(text, errorCorrectLevel) {\n  var len = _getUTF8Length(text);\n  // QRCodeLimitLength[39][levelIndex] is the type-40 max\n  var idx = errorCorrectLevel; // map L=0,M=1,Q=2,H=3 per package\n  return len <= QRCodeLimitLength[39][idx];\n}","typeGuard":"null","tryCatchPattern":"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; }","preventionTips":["Use correctLevel L for maximum capacity when resilience is less important.","Shorten URLs before encoding (use a shortener).","Cap and validate input length before constructing the QR code.","For large payloads, host the data and encode only a link."],"tags":["qrcode","encoding","capacity","limit"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}