{"record":{"id":"e669d7bae647e707","repo":"slackhq/nebula","slug":"error-while-writing-out-qr-s-e669d7","errorCode":null,"errorMessage":"error while writing out-qr: %s","messagePattern":"error while writing out-qr: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/nebula-cert/print.go","lineNumber":110,"sourceCode":"\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\"))\n\tout.Write([]byte(stdioHelpText))\n\tpf.set.SetOutput(out)\n\tpf.set.PrintDefaults()\n}\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/cmd/nebula-cert/print.go#L92-L128","documentation":"After the QR image is generated, printCert writes the PNG bytes via writeOutput(*pf.outQRPath, b, 0600, out); failure is wrapped as \"error while writing out-qr\". It means the QR PNG could not be persisted to the -out-qr destination (or written to stdout when -out-qr is stdio). The QR was generated fine; only the write failed.","triggerScenarios":"`nebula-cert print -path cert.crt -out-qr /dir/qr.png` where /dir does not exist, is unwritable, is a directory itself, or the filesystem is full; stdio mode where stdout cannot be written (closed pipe)","commonSituations":"--out-qr pointing into a nonexistent directory; running as a user without write access to the output location; redirecting binary stdout into a closed pipe; read-only container filesystem","solutions":["Create the output directory (mkdir -p) and ensure permissions allow writing","Verify -out-qr is a file path, not an existing directory","Free disk space if the write failed with ENOSPC","Redirect stdout properly when using stdio mode (e.g. `> qr.png`) and avoid closed pipes"],"exampleFix":"// before\nnebula-cert print -path host.crt -out-qr /etc/nebula/nope/qr.png\n// after\nmkdir -p /etc/nebula && nebula-cert print -path host.crt -out-qr /etc/nebula/qr.png","handlingStrategy":"validation","validationCode":"qrPath := *pf.outQRPath\nif st, err := os.Stat(filepath.Dir(qrPath)); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"out-qr directory %q missing\", filepath.Dir(qrPath))\n}\nif st, err := os.Stat(qrPath); err == nil && st.IsDir() {\n    return fmt.Errorf(\"out-qr path %q is a directory\", qrPath)\n}","typeGuard":null,"tryCatchPattern":"if err := printCert(args, out, errOut); err != nil {\n    if strings.Contains(err.Error(), \"error while writing out-qr\") {\n        log.Printf(\"cannot write QR to %s: %v\", *pf.outQRPath, err)\n    }\n}","preventionTips":["mkdir -p the QR output directory beforehand","Ensure -out-qr is a file path with a writable parent","In stdio mode, redirect stdout to a file and keep the pipe open","Check free disk space before generating QR images"],"tags":["filesystem","file-write","qrcode","nebula-cert"],"backgroundTag":"file-write-permission-denied","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"}