wagoodman/dive · error
cannot marshal export payload: %w
Error message
cannot marshal export payload: %w
What it means
Returned by ExportTo when building the JSON export payload via export.NewExport(analysis).Marshal() fails. The analysis object is converted to an export structure and serialized; marshalling only fails if the payload contains values Go's json encoder cannot represent — most notably NaN/Inf float fields (efficiency or size ratios) produced by degenerate analyses such as zero-byte images.
Source
Thrown at cmd/dive/cli/internal/command/adapter/exporter.go:47
func (e *jsonExporter) ExportTo(ctx context.Context, analysis *image.Analysis, path string) error {
log.WithFields("path", path).Infof("exporting analysis")
mon := bus.StartTask(payload.GenericTask{
Title: payload.Title{
Default: "Exporting details",
WhileRunning: "Exporting details",
OnSuccess: "Exported details",
},
HideOnSuccess: false,
HideStageOnSuccess: false,
ID: analysis.Image,
Context: fmt.Sprintf("[file: %s]", path),
})
bytes, err := export.NewExport(analysis).Marshal()
if err != nil {
mon.SetError(err)
return fmt.Errorf("cannot marshal export payload: %w", err)
} else {
mon.SetCompleted()
}
file, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return fmt.Errorf("cannot open export file: %w", err)
}
defer file.Close()
_, err = file.Write(bytes)
if err != nil {
return fmt.Errorf("cannot write to export file: %w", err)
}
return nil
}
View on GitHub (pinned to d6c691947f)
Solutions
- Verify the image is a real, non-empty image (docker save and check size); try a known-good image like alpine to confirm the export path works
- Upgrade dive — NaN-guarding in the export marshalling has been addressed in newer versions
- If it reproduces, capture the analysis (run without --json) and report the image manifest details upstream
- As a workaround for CI, drop --json and rely on the text/CI output until fixed
Defensive patterns
Strategy: try-catch
Validate before calling
// reject degenerate images before exporting
if analysis.SizeBytes == 0 {
return fmt.Errorf("cannot export zero-byte image analysis")
} Try / catch
if err := exporter.ExportTo(ctx, analysis, path); err != nil {
if strings.Contains(err.Error(), "cannot marshal export payload") {
// payload problem (often NaN metrics): report image details upstream,
// fall back to human-readable CI output
}
return err
} Prevention
- Smoke-test --json on a known-good image when adding export to CI
- Keep dive current so NaN-guard fixes in marshalling are picked up
- Report images that trigger marshal failures — they indicate upstream metric bugs
When it happens
Trigger: Running dive with --json <path> (export.jsonPath set) on an analysis whose computed metrics include NaN or +Inf — e.g. an image with zero total bytes or zero reference bytes, making an efficiency ratio 0/0.
Common situations: Exporting a tiny FROM scratch image that only COPYs an empty file, or a synthetic/test image with no file content; also possible after an analyzer change introduces an uninitialized metric field.
Related errors
- cannot open export file: %w
- cannot write to export file: %w
- cannot export analysis: %w
- directory for JSON export does not exist: %s
- failed to unmarshal docker config: %w
AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15).
Data as JSON: /api/errors/377cecbea282074b.
Report an issue: GitHub.