{"record":{"id":"97f6afb04a65e6ec","repo":"chenhg5/cc-connect","slug":"encode-qr-w","errorCode":null,"errorMessage":"encode QR: %w","messagePattern":"encode QR: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/feishu.go","lineNumber":705,"sourceCode":"\t\treturn\n\t}\n\tqrterminal.GenerateWithConfig(content, qrterminal.Config{\n\t\tLevel:      qrterminal.M,\n\t\tWriter:     os.Stdout,\n\t\tHalfBlocks: false,\n\t\tBlackChar:  \"██\",\n\t\tWhiteChar:  \"  \",\n\t\tQuietZone:  4,\n\t})\n\tif _, err := fmt.Fprintln(os.Stdout); err != nil {\n\t\treturn\n\t}\n}\n\nfunc saveQRCodeImage(content, path string) error {\n\tcode, err := qr.Encode(content, qr.M)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encode QR: %w\", err)\n\t}\n\tcode.Scale = 8\n\treturn os.WriteFile(path, code.PNG(), 0644)\n}\n","sourceCodeStart":687,"sourceCodeEnd":710,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/feishu.go#L687-L710","documentation":"saveQRCodeImage wraps any failure from the qrcode encoder (rsc.io/qr) as \"encode QR: %w\". This happens before any file I/O, so it means the QR content itself could not be encoded at the requested M (medium) error-correction level. It indicates the data is too long or invalid for a QR code at level M.","triggerScenarios":"saveQRCodeImage(content, path) is called by runRegistrationFlow, runWeixinQRLoginFlow, and tests; qr.Encode returns an error when the content exceeds the maximum byte capacity of a QR code at error-correction level M, or the input cannot be encoded.","commonSituations":"A login/registration URL or token returned by Feishu/Weixin is unusually long (very long signed URLs, oversized tokens), pushing the payload past QR capacity at level M.","solutions":["Shorten the content being encoded: strip query parameters or use a shorter URL for the QR payload.","Lower the error-correction level in saveQRCodeImage from qr.M to qr.L to increase capacity.","Check the wrapped error (%w) to confirm it is an overflow vs. invalid input from qr.Encode."],"exampleFix":"// before\ncode, err := qr.Encode(content, qr.M)\n// after\ncode, err := qr.Encode(content, qr.L) // higher capacity, still scannable","handlingStrategy":"try-catch","validationCode":"if len(content) > 2000 {\n    return fmt.Errorf(\"QR content too long: %d bytes\", len(content))\n}","typeGuard":null,"tryCatchPattern":"if err := saveQRCodeImage(content, path); err != nil {\n    var encErr error\n    if strings.Contains(err.Error(), \"encode QR:\") {\n        encErr = fmt.Errorf(\"QR payload too large for level M: %w\", err)\n    }\n    return encErr\n}","preventionTips":["Keep QR payloads (login URLs/tokens) short before encoding.","Bound-check content length before calling saveQRCodeImage.","Use qr.L for long payloads."],"tags":["qrcode","encoding","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}