{"record":{"id":"b3f922f261a0cb8b","repo":"cilium/cilium","slug":"failed-to-parse-text-w","errorCode":null,"errorMessage":"failed to parse text: %w","messagePattern":"failed to parse text: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cilium-cli/encrypt/status.go","lineNumber":137,"sourceCode":"\nfunc (s *Encrypt) fetchEncryptStatusFromPod(ctx context.Context, pod corev1.Pod) (models.EncryptionStatus, error) {\n\tcmd := []string{\"cilium\", \"encrypt\", \"status\", \"-o\", \"json\"}\n\toutput, err := s.client.ExecInPod(ctx, pod.Namespace, pod.Name, defaults.AgentContainerName, cmd)\n\tif err != nil {\n\t\treturn models.EncryptionStatus{}, fmt.Errorf(\"failed to fetch encryption status from %s: %w\", pod.Name, err)\n\t}\n\tencStatus, err := nodeStatusFromOutput(output.String())\n\tif err != nil {\n\t\treturn models.EncryptionStatus{}, fmt.Errorf(\"failed to parse encryption status from %s: %w\", pod.Name, err)\n\t}\n\treturn encStatus, nil\n}\n\nfunc nodeStatusFromOutput(output string) (models.EncryptionStatus, error) {\n\tif !json.Valid([]byte(output)) {\n\t\tres, err := nodeStatusFromText(output)\n\t\tif err != nil {\n\t\t\treturn models.EncryptionStatus{}, fmt.Errorf(\"failed to parse text: %w\", err)\n\t\t}\n\t\treturn res, nil\n\t}\n\tencStatus := models.EncryptionStatus{}\n\tif err := json.Unmarshal([]byte(output), &encStatus); err != nil {\n\t\treturn models.EncryptionStatus{}, fmt.Errorf(\"failed to unmarshal json: %w\", err)\n\t}\n\treturn encStatus, nil\n}\n\nfunc nodeStatusFromText(str string) (models.EncryptionStatus, error) {\n\tres := models.EncryptionStatus{\n\t\tIpsec: &models.IPsecStatus{\n\t\t\tDecryptInterfaces: make([]string, 0),\n\t\t\tXfrmErrors:        make(map[string]int64),\n\t\t},\n\t\tWireguard: &models.WireguardStatus{\n\t\t\tInterfaces: make([]*models.WireguardInterface, 0),","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/cilium-cli/encrypt/status.go#L119-L155","documentation":"Returned by nodeStatusFromOutput when the exec output is not valid JSON, so the CLI falls back to nodeStatusFromText (line-oriented `key: value` parsing), and that text parser also fails. The library tries JSON first, then a plain-text fallback modeled on `cilium encrypt status` human output.","triggerScenarios":"`cilium encrypt status` output is neither valid JSON nor well-formed text: e.g. a line like `Keys in use: not-a-number` hits strconv.Atoi failure inside nodeStatusFromText, or unexpected keys with non-numeric values in the default xfrm-error branch.","commonSituations":"Older or patched cilium-agent emitting changed text format; output polluted by warnings before status lines; non-English locale or new fields with textual values; unit tests feeding malformed fixtures (see Test_nodeStatusFromOutput).","solutions":["Inspect the raw output with `kubectl exec ... -- cilium encrypt status` and compare against the expected `key: value` lines","Upgrade the Cilium agent so JSON output (-o json) is valid and the text fallback is not needed","If a new field has non-numeric values, update nodeStatusFromText to handle the new key explicitly","Report/patch the parser in cilium-cli/encrypt/status.go if the agent format changed legitimately"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !json.Valid([]byte(output)) && !strings.Contains(output, \"Keys in use\") {\n    // output matches neither expected format; don't attempt parse\n}","typeGuard":"func looksLikeEncryptStatusText(s string) bool {\n    for _, key := range []string{\"Encryption\", \"Keys in use\", \"Errors\"} {\n        if strings.Contains(s, key+\":\") { return true }\n    }\n    return false\n}","tryCatchPattern":"res, err := nodeStatusFromOutput(output)\nif err != nil {\n    return fmt.Errorf(\"agent output unparseable; raw=%q: %w\", truncate(output, 200), err)\n}","preventionTips":["Log/truncate raw output whenever parsing fails to aid debugging","Pin cilium-cli versions to matching Cilium releases","Keep fixtures in Test_nodeStatusFromOutput updated with real agent output"],"tags":["cilium","parse-error","text-parsing"],"backgroundTag":"pod-exec-output-parse-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}