{"record":{"id":"2636c3eca1c745f3","repo":"slackhq/nebula","slug":"error-while-generating-qr-code-s-2636c3","errorCode":null,"errorMessage":"error while generating qr code: %s","messagePattern":"error while generating qr code: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/nebula-cert/print.go","lineNumber":105,"sourceCode":"\t\t}\n\n\t\tif rawCert == nil || len(rawCert) == 0 || strings.TrimSpace(string(rawCert)) == \"\" {\n\t\t\tbreak\n\t\t}\n\n\t\tpart++\n\t}\n\n\tif *pf.json && !qrToStdout {\n\t\tb, _ := json.Marshal(jsonCerts)\n\t\t_, _ = out.Write(b)\n\t\t_, _ = out.Write([]byte(\"\\n\"))\n\t}\n\n\tif *pf.outQRPath != \"\" {\n\t\tb, err := qrcode.Encode(string(qrBytes), qrcode.Medium, -5)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while generating qr code: %s\", err)\n\t\t}\n\n\t\terr = writeOutput(*pf.outQRPath, b, 0600, out)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while writing out-qr: %s\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc printSummary() string {\n\treturn \"print <flags>: prints details about a certificate\"\n}\n\nfunc printHelp(out io.Writer) {\n\tpf := newPrintFlags()\n\tout.Write([]byte(\"Usage of \" + os.Args[0] + \" \" + printSummary() + \"\\n\"))","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cmd/nebula-cert/print.go#L87-L123","documentation":"After collecting the PEM bytes, printCert encodes them into a QR image with qrcode.Encode(string(qrBytes), qrcode.Medium, -5); an encoding failure is wrapped as \"error while generating qr code\". This happens when the payload exceeds what a QR code at the chosen recovery level can physically store.","triggerScenarios":"`nebula-cert print ... -out-qr out.png` where qrBytes (one or more full certificate PEMs) exceed the QR medium-recovery capacity, or the qrcode library rejects the data size at the given recovery level (-5 means minimum size hint)","commonSituations":"printing very large certificates (long host names, many groups, big public keys) or multi-certificate bundles where combined PEM size exceeds QR capacity; requesting QR of an entire CA-signed bundle","solutions":["Reduce certificate size: shorten group names/host name, or fewer groups","QR-encode a single certificate instead of a multi-cert bundle","Use a larger output or lower-capacity requirement: try a different recovery level / newer qrcode library version","Distribute the payload across multiple QR outputs rather than one"],"exampleFix":"// before\nnebula-cert print -path ca-and-host-bundle.crt -out-qr qr.png   # bundle too large for one QR\n// after\nnebula-cert print -path host.crt -out-qr qr.png                 # single cert fits","handlingStrategy":"validation","validationCode":"pemLen := len(strings.TrimSpace(pemData))\nif pemLen > 2000 {\n    return fmt.Errorf(\"payload of %d bytes too large for a single QR code\", pemLen)\n}","typeGuard":null,"tryCatchPattern":"if err := printCert(args, out, errOut); err != nil {\n    if strings.Contains(err.Error(), \"error while generating qr code\") {\n        log.Printf(\"cert too large for QR: %v; print without -out-qr instead\", err)\n    }\n}","preventionTips":["Keep certificates small: short host/group names","QR-encode only single certificates, not bundles","Fall back to file/PEM distribution when certs are large","Test QR output with your largest real certificate"],"tags":["qrcode","encoding","payload-size","nebula-cert"],"backgroundTag":"qrcode-payload-too-large","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}