{"record":{"id":"02532259d9147f4b","repo":"kopia/kopia","slug":"unable-to-marshal-log-entry-bytes","errorCode":null,"errorMessage":"unable to marshal log entry bytes","messagePattern":"unable to marshal log entry bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/content/indexblob/index_blob_manager_v0.go","lineNumber":189,"sourceCode":"\t\treturn nil, errors.Wrap(err, \"error cleaning up index blobs\")\n\t}\n\n\tif compacted {\n\t\treturn &maintenancestats.CompactIndexesStats{\n\t\t\tDroppedContentsDeletedBefore: opt.DropDeletedBefore,\n\t\t}, nil\n\t}\n\n\treturn nil, nil\n}\n\nfunc (m *ManagerV0) registerCompaction(ctx context.Context, inputs, outputs []blob.Metadata, maxEventualConsistencySettleTime time.Duration) error {\n\tlogEntryBytes, err := json.Marshal(&compactionLogEntry{\n\t\tInputMetadata:  inputs,\n\t\tOutputMetadata: outputs,\n\t})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"unable to marshal log entry bytes\")\n\t}\n\n\tcompactionLogBlobMetadata, err := m.enc.EncryptAndWriteBlob(ctx, gather.FromSlice(logEntryBytes), V0CompactionLogBlobPrefix, \"\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"unable to write compaction log\")\n\t}\n\n\tcontentlog.Log4(ctx, m.log,\n\t\t\"registered compaction\",\n\t\tblobparam.BlobMetadataList(\"inputs\", inputs),\n\t\tblobparam.BlobMetadataList(\"outputs\", outputs),\n\t\tblobparam.BlobID(\"compactionLogBlobID\", compactionLogBlobMetadata.BlobID),\n\t\tlogparam.Time(\"compactionLogBlobTimestamp\", compactionLogBlobMetadata.Timestamp))\n\n\tif err := m.deleteOldBlobs(ctx, compactionLogBlobMetadata, maxEventualConsistencySettleTime); err != nil {\n\t\treturn errors.Wrap(err, \"error deleting old index blobs\")\n\t}\n","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/content/indexblob/index_blob_manager_v0.go#L171-L207","documentation":"Wraps a failure from json.Marshal of the compactionLogEntry struct in registerCompaction (index_blob_manager_v0.go:189). The compaction log entry (input/output blob metadata) must be serialized to JSON before being encrypted and stored; marshaling fails only if the payload cannot be encoded (e.g. unsupported value types such as NaN-like or invalid data in the metadata). This is effectively an internal invariant violation — the struct is plain JSON-serializable data.","triggerScenarios":"json.Marshal(&compactionLogEntry{...}) returns an error while registerCompaction runs — practically only when InputMetadata/OutputMetadata contain values json cannot encode.","commonSituations":"Very rare; would indicate corrupted or unexpected blob.Metadata contents, a Go stdlib marshal failure, or memory exhaustion during very large compactions.","solutions":["Inspect the wrapped marshal error for which value could not be encoded.","Verify blob.Metadata values passed as inputs/outputs are well-formed (no invalid fields).","Upgrade the library if the error persists with plain metadata; report as a bug since compactionLogEntry is expected to always marshal."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: verify compaction metadata is JSON-encodable before registering\nif _, err := json.Marshal(&compactionLogEntry{InputMetadata: inputs, OutputMetadata: outputs}); err != nil {\n\treturn errors.Wrap(err, \"compaction metadata not serializable\")\n}","typeGuard":"func validMetadata(in, out []blob.Metadata) bool {\n\tfor _, m := range append(append([]blob.Metadata{}, in...), out...) {\n\t\tif m.BlobID == \"\" { return false }\n\t}\n\treturn true\n}","tryCatchPattern":"if err := m.registerCompaction(ctx, inputs, outputs, settleTime); err != nil {\n\tif strings.Contains(err.Error(), \"unable to marshal log entry bytes\") {\n\t\t// invariant violation: inspect blob.Metadata contents / report bug\n\t}\n\treturn err\n}","preventionTips":["Treat marshal failures here as bugs: compactionLogEntry is plain JSON data.","Validate blob.Metadata passed into compaction is well-formed.","Keep the Go stdlib and library versions current to avoid known marshal issues."],"tags":["json","marshal","compaction","go"],"backgroundTag":"json-marshal-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}