{"record":{"id":"5c1d7852f1cc9d9a","repo":"wechaty/wechaty","slug":"qr-code-value-is-larger-than-the-max-len-did-you","errorCode":null,"errorMessage":"QR Code Value is larger than the max len. Did you return the image base64 text by mistake? See: https://github.com/wechaty/wechaty/issues/1889","messagePattern":"QR Code Value is larger than the max len\\. Did you return the image base64 text by mistake\\? See: https://github\\.com/wechaty/wechaty/issues/1889","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pure-functions/guard-qr-code-value.ts","lineNumber":24,"sourceCode":" *\n *   Licensed under the Apache License, Version 2.0 (the \"License\");\n *   you may not use this file except in compliance with the License.\n *   You may obtain a copy of the License at\n *\n *       http://www.apache.org/licenses/LICENSE-2.0\n *\n *   Unless required by applicable law or agreed to in writing, software\n *   distributed under the License is distributed on an \"AS IS\" BASIS,\n *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *   See the License for the specific language governing permissions and\n *   limitations under the License.\n *\n */\nconst MAX_LEN = 7089\n\nexport function guardQrCodeValue (value: string): string {\n  if (value.length > MAX_LEN) {\n    throw new Error('QR Code Value is larger than the max len. Did you return the image base64 text by mistake? See: https://github.com/wechaty/wechaty/issues/1889')\n  }\n  return value\n}\n","sourceCodeStart":6,"sourceCodeEnd":28,"githubUrl":"https://github.com/wechaty/wechaty/blob/5a0520ac7d0567777d6931eee53f81bbfcae1453/src/pure-functions/guard-qr-code-value.ts#L6-L28","documentation":"guardQrCodeValue() enforces that QR code string values do not exceed MAX_LEN = 7089 characters, the capacity of a version-40 QR code. If the value passed to it is longer — almost always because someone returned an image (e.g. base64 PNG data) instead of the QR payload text — it throws with a pointer to issue #1889. This is a data-shape sanity guard on puppet callbacks.","triggerScenarios":"A puppet implementation's onLogin/onScan callback (or contactSelfQRCode path) returns base64 image data or an HTML data-URI as the qrcode value, and guardQrCodeValue (called from qrcode()/qrCode()) receives it.","commonSituations":"Custom or buggy puppet services returning screenshot/base64 images for the login QR; developers implementing their own puppet returning FileBox base64 text instead of the encoded QR content.","solutions":["Fix the puppet implementation to return the QR payload text (the encoded string), not an image or its base64.","If you must show an image, generate the QR image from the short payload string on the client side (e.g. qrcode-terminal) rather than passing it through.","Check for accidental FileBox.toBase64() or buffer.toString('base64') calls in the puppet's QR code path.","Update the puppet service package — this bug was fixed in mainstream puppets after wechaty issue #1889."],"exampleFix":"// before (puppet onScan)\nonScan(qrcode) { emit('scan', Buffer.from(qrcode).toString('base64')) }\n// after\nonScan(qrcode) { emit('scan', qrcode) } // pass the raw QR payload string","handlingStrategy":"validation","validationCode":"const MAX_QR_LEN = 7089\nfunction isQrCodeValue(v) {\n  return typeof v === 'string' && v.length <= MAX_QR_LEN\n}\n// before using a puppet-provided qrcode value\nif (!isQrCodeValue(qrValue)) {\n  console.warn('qrcode value looks like an image, not a QR payload')\n}","typeGuard":"function isQrCodePayload(v: unknown): v is string {\n  return typeof v === 'string' && v.length <= 7089\n}","tryCatchPattern":"try {\n  const qr = await bot.userSelf().qrcode()\n} catch (e) {\n  if (String(e.message).includes('QR Code Value is larger than the max len')) {\n    console.error('Puppet returned image data instead of QR payload; fix or update the puppet')\n  }\n  throw e\n}","preventionTips":["Keep puppet-service implementations updated (post-#1889 puppets return the payload text).","Never pass FileBox/base64 image output into QR-code fields.","Add a length check on QR values in custom puppet code before emitting them."],"tags":["qrcode","validation","puppet-implementation"],"backgroundTag":"qr-code-value-too-long","analyzedSha":"5a0520ac7d0567777d6931eee53f81bbfcae1453","analyzedAt":"2026-09-01T01:57:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}