{"record":{"id":"377cecbea282074b","repo":"wagoodman/dive","slug":"cannot-marshal-export-payload-w","errorCode":null,"errorMessage":"cannot marshal export payload: %w","messagePattern":"cannot marshal export payload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/command/adapter/exporter.go","lineNumber":47,"sourceCode":"func (e *jsonExporter) ExportTo(ctx context.Context, analysis *image.Analysis, path string) error {\n\tlog.WithFields(\"path\", path).Infof(\"exporting analysis\")\n\n\tmon := bus.StartTask(payload.GenericTask{\n\t\tTitle: payload.Title{\n\t\t\tDefault:      \"Exporting details\",\n\t\t\tWhileRunning: \"Exporting details\",\n\t\t\tOnSuccess:    \"Exported details\",\n\t\t},\n\t\tHideOnSuccess:      false,\n\t\tHideStageOnSuccess: false,\n\t\tID:                 analysis.Image,\n\t\tContext:            fmt.Sprintf(\"[file: %s]\", path),\n\t})\n\n\tbytes, err := export.NewExport(analysis).Marshal()\n\tif err != nil {\n\t\tmon.SetError(err)\n\t\treturn fmt.Errorf(\"cannot marshal export payload: %w\", err)\n\t} else {\n\t\tmon.SetCompleted()\n\t}\n\n\tfile, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open export file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\t_, err = file.Write(bytes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot write to export file: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":29,"sourceCodeEnd":64,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/command/adapter/exporter.go#L29-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// reject degenerate images before exporting\nif analysis.SizeBytes == 0 {\n    return fmt.Errorf(\"cannot export zero-byte image analysis\")\n}","typeGuard":null,"tryCatchPattern":"if err := exporter.ExportTo(ctx, analysis, path); err != nil {\n    if strings.Contains(err.Error(), \"cannot marshal export payload\") {\n        // payload problem (often NaN metrics): report image details upstream,\n        // fall back to human-readable CI output\n    }\n    return err\n}","preventionTips":["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"],"tags":["export","json","marshal","nan","metrics"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}