{"record":{"id":"d4a3a538bf0107dd","repo":"cilium/cilium","slug":"invalid-label-empty-data","errorCode":null,"errorMessage":"invalid Label: empty data","messagePattern":"invalid Label: empty data","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/labels/labels.go","lineNumber":492,"sourceCode":"\tif len(l.Value) != 0 {\n\t\tbuf.WriteString(\"=\")\n\t\tbuf.WriteString(l.Value)\n\t}\n}\n\n// IsValid returns true if Key != \"\".\nfunc (l *Label) IsValid() bool {\n\treturn l.Key != \"\"\n}\n\n// UnmarshalJSON TODO create better explanation about unmarshall with examples\nfunc (l *Label) UnmarshalJSON(data []byte) error {\n\tif l == nil {\n\t\treturn fmt.Errorf(\"cannot unmarshal to nil pointer\")\n\t}\n\n\tif len(data) == 0 {\n\t\treturn fmt.Errorf(\"invalid Label: empty data\")\n\t}\n\n\tvar aux struct {\n\t\tSource string `json:\"source\"`\n\t\tKey    string `json:\"key\"`\n\t\tValue  string `json:\"value,omitempty\"`\n\t}\n\n\terr := json.Unmarshal(data, &aux)\n\tif err != nil {\n\t\t// If parsing of the full representation failed then try the short\n\t\t// form in the format:\n\t\t//\n\t\t// [SOURCE:]KEY[=VALUE]\n\t\tvar aux string\n\n\t\tif err := json.Unmarshal(data, &aux); err != nil {\n\t\t\treturn fmt.Errorf(\"decode of Label as string failed: %w\", err)","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/labels/labels.go#L474-L510","documentation":"Label.UnmarshalJSON returns this error when the raw JSON data slice is empty (len(data) == 0). An empty byte slice carries no JSON value at all, so the Label cannot be decoded. Note this is distinct from JSON \"null\" or \"\", which follow other code paths.","triggerScenarios":"Calling json.Unmarshal([]byte{}, &label) or Label.UnmarshalJSON(nil), or a decoder feeding zero bytes into Label.UnmarshalJSON.","commonSituations":"Reading a truncated or zero-length file into a Label; a config loader that skips empty values but still calls Unmarshal; passing nil byte slices from tests or IPC buffers that failed to populate.","solutions":["Ensure the JSON input is non-empty before decoding; check the source file/buffer actually contains data","Handle empty input upstream: if len(data) == 0, skip decoding or default the Label instead of calling UnmarshalJSON","Fix the producer side that emitted an empty payload (truncated write, early EOF)","If an empty value is legal in your config, represent it explicitly as JSON \"null\" or \"\" and handle those branches"],"exampleFix":"// before\nif err := lbl.UnmarshalJSON(raw); err != nil { ... } // raw may be empty\n// after\nif len(raw) == 0 {\n\treturn nil // or set a default label\n}\nif err := lbl.UnmarshalJSON(raw); err != nil { ... }","handlingStrategy":"validation","validationCode":"if len(data) == 0 {\n\treturn nil // nothing to decode; use default or skip\n}","typeGuard":null,"tryCatchPattern":"if err := lbl.UnmarshalJSON(data); err != nil {\n\tif err.Error() == \"invalid Label: empty data\" {\n\t\treturn fmt.Errorf(\"empty JSON payload for Label: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Check input files/buffers are non-empty before decoding","Fix producers that emit truncated or zero-byte payloads","Treat empty config values as 'absent' and skip decoding rather than calling Unmarshal","Add pre-decode assertions in loaders that read from files or IPC"],"tags":["cilium","labels","json","unmarshal"],"backgroundTag":"json-empty-input","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}