cilium/cilium · error
error formatting summary: %v error: %w
Error message
error formatting summary: %v error: %w
What it means
In the perf connectivity tests, exportSummary serializes collected perfData to JSON (via prettyPrintJSON) and writes a perfdash-formatted file. If JSON marshaling of the summary fails, the error is wrapped with this message including the content being formatted. This means the performance results could not be serialized, so the benchmark report file is not produced.
Source
Thrown at cilium-cli/connectivity/perf/common/metrics.go:192
if summary.Result.ThroughputMetric != nil {
res := summary.Result.ThroughputMetric.toPerfData(labels, summary.PerfTest.Test+"_"+summary.PerfTest.Scenario)
if _, ok := data[identifier+"th"]; !ok {
data[identifier+"th"] = res
} else {
maps.Copy(data[identifier+"th"].Data, res.Data)
}
}
}
return exportSummary(perfData{Version: "v1", DataItems: slices.Collect(maps.Values(data))}, reportDir)
}
func exportSummary(content perfData, reportDir string) error {
// this filename needs to be in a specific format for perfdash
fileName := strings.Join([]string{"NetworkPerformance_benchmark", time.Now().Format(time.RFC3339)}, "_")
filePath := path.Join(reportDir, strings.Join([]string{fileName, "json"}, "."))
contentStr, err := prettyPrintJSON(content)
if err != nil {
return fmt.Errorf("error formatting summary: %v error: %w", content, err)
}
if err := os.WriteFile(filePath, []byte(contentStr), 0600); err != nil {
return fmt.Errorf("writing to file %v error: %w", filePath, err)
}
return nil
}
func prettyPrintJSON(data any) (string, error) {
output := &bytes.Buffer{}
if err := json.NewEncoder(output).Encode(data); err != nil {
return "", fmt.Errorf("building encoder error: %w", err)
}
formatted := &bytes.Buffer{}
if err := json.Indent(formatted, output.Bytes(), "", " "); err != nil {
return "", fmt.Errorf("indenting error: %w", err)
}
return formatted.String(), nil
}View on GitHub (pinned to ac7b90affa)
Solutions
- Inspect the wrapped inner error and the printed content to find the field that fails to marshal
- Check any custom MarshalJSON methods on perfData fields for returning errors (e.g. NaN/Inf values)
- Fix the data at collection time so all perfData values are JSON-serializable
- Validate with a quick json.Marshal(perfData{...}) unit test for new fields
Example fix
// before
contentStr, err := prettyPrintJSON(content)
if err != nil {
return fmt.Errorf("error formatting summary: %v error: %w", content, err)
}
// after
contentStr, err := prettyPrintJSON(sanitizePerfData(content)) // replace NaN/Inf with 0 before marshaling
if err != nil {
return fmt.Errorf("error formatting summary: %v error: %w", content, err)
} Defensive patterns
Strategy: validation
Validate before calling
func validateSerializable(data perfData) error {
b, err := json.Marshal(data)
if err != nil { return err }
if bytes.Contains(b, []byte("NaN")) || bytes.Contains(b, []byte("Inf")) {
return fmt.Errorf("non-JSON numbers in perf data")
}
return nil
}
// call validateSerializable(content) before exportSummary Type guard
func isJSONSerializable(v any) bool {
_, err := json.Marshal(v)
return err == nil
} Try / catch
if err := exportSummary(content, reportDir); err != nil {
if strings.Contains(err.Error(), "error formatting summary") {
log.Printf("perf data not serializable, skipping perfdash export: %v", err)
return nil // or fix the offending field
}
return err
} Prevention
- Keep perfData fields limited to JSON-safe types (string, float64, int)
- Sanitize NaN/Inf metric values at collection time
- Add a unit test marshaling representative perfData
When it happens
Trigger: prettyPrintJSON returns an error for the given perfData — i.e. json.NewEncoder(...).Encode(data) fails while marshaling the summary structure (unsupported type such as a channel/func field, or a cyclic data structure).
Common situations: A perfData entry accidentally holds a non-serializable value (e.g. an error value stored in a map with a bad type, NaN/Inf in a custom MarshalJSON, or a custom MarshalJSON returning an error); regression after adding a field to perfData.
Related errors
- failed to marshal status to JSON
- building encoder error: %w
- indenting error: %w
- dump constants: %w
- failed to parse restored endpoint: %w
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/9aab42062abd6ca6.
Report an issue: GitHub.