cilium/cilium · error
invalid Label: empty data
Error message
invalid Label: empty data
What it means
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.
Source
Thrown at pkg/labels/labels.go:492
if len(l.Value) != 0 {
buf.WriteString("=")
buf.WriteString(l.Value)
}
}
// IsValid returns true if Key != "".
func (l *Label) IsValid() bool {
return l.Key != ""
}
// UnmarshalJSON TODO create better explanation about unmarshall with examples
func (l *Label) UnmarshalJSON(data []byte) error {
if l == nil {
return fmt.Errorf("cannot unmarshal to nil pointer")
}
if len(data) == 0 {
return fmt.Errorf("invalid Label: empty data")
}
var aux struct {
Source string `json:"source"`
Key string `json:"key"`
Value string `json:"value,omitempty"`
}
err := json.Unmarshal(data, &aux)
if err != nil {
// If parsing of the full representation failed then try the short
// form in the format:
//
// [SOURCE:]KEY[=VALUE]
var aux string
if err := json.Unmarshal(data, &aux); err != nil {
return fmt.Errorf("decode of Label as string failed: %w", err)View on GitHub (pinned to ac7b90affa)
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
Example fix
// before
if err := lbl.UnmarshalJSON(raw); err != nil { ... } // raw may be empty
// after
if len(raw) == 0 {
return nil // or set a default label
}
if err := lbl.UnmarshalJSON(raw); err != nil { ... } Defensive patterns
Strategy: validation
Validate before calling
if len(data) == 0 {
return nil // nothing to decode; use default or skip
} Try / catch
if err := lbl.UnmarshalJSON(data); err != nil {
if err.Error() == "invalid Label: empty data" {
return fmt.Errorf("empty JSON payload for Label: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: Calling json.Unmarshal([]byte{}, &label) or Label.UnmarshalJSON(nil), or a decoder feeding zero bytes into Label.UnmarshalJSON.
Common situations: 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.
Related errors
- cannot unmarshal to nil pointer
- decode of Label as string failed: %w
- invalid Label: Failed to parse %s as a string
- AddrCluster.UnmarshalJSON: bad address
- unmarshaling Cilium stdout json: %w
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/d4a3a538bf0107dd.
Report an issue: GitHub.