{"record":{"id":"ad82caaf20932393","repo":"kopia/kopia","slug":"error-processing-snapshot-v","errorCode":null,"errorMessage":"error processing snapshot %v","messagePattern":"error processing snapshot (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"snapshot/snapshotfs/dir_rewriter.go","lineNumber":229,"sourceCode":"}\n\nfunc (rw *DirRewriter) equalEntries(e1, e2 *snapshot.DirEntry) bool {\n\tif e1 == nil {\n\t\treturn e2 == nil\n\t}\n\n\tif e2 == nil {\n\t\treturn false\n\t}\n\n\treturn rw.getCacheKey(e1) == rw.getCacheKey(e2)\n}\n\n// RewriteSnapshotManifest rewrites the directory tree starting at a given manifest.\nfunc (rw *DirRewriter) RewriteSnapshotManifest(ctx context.Context, man *snapshot.Manifest, metadataComp compression.Name) (bool, error) {\n\tnewEntry, err := rw.getCachedReplacement(ctx, \".\", man.RootEntry, metadataComp)\n\tif err != nil {\n\t\treturn false, errors.Wrapf(err, \"error processing snapshot %v\", man.ID)\n\t}\n\n\tif newEntry == nil {\n\t\tnewEntry, err = rw.opts.OnDirectoryReadFailure(ctx, \".\", man.RootEntry, errors.Errorf(\"invalid root directory %v\", man.ID))\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\t}\n\n\tif !rw.equalEntries(newEntry, man.RootEntry) {\n\t\tman.RootEntry = newEntry\n\t\treturn true, nil\n\t}\n\n\treturn false, nil\n}\n\n// Close closes the rewriter.","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/snapshot/snapshotfs/dir_rewriter.go#L211-L247","documentation":"RewriteSnapshotManifest wraps any error from processing the snapshot's root entry via getCachedReplacement, annotated with the snapshot's ID. It means the root directory tree could not be rewritten — the failure could be anywhere in the tree (object open, child rewrite, manifest write), all aggregated here.","triggerScenarios":"rw.getCachedReplacement(ctx, \".\", man.RootEntry, metadataComp) returns an error when rewriting the root entry of snapshot man.ID; e.g. root directory object unreadable, nested child failure wrapped by its name, cache get/unmarshal failure.","commonSituations":"Running kopia snapshot repair/migration (e.g. after compression changes or maintenance rewrite) against a repository with damaged or missing root directory objects, storage outages, or snapshot manifests referencing pruned blobs.","solutions":["Look at the full wrapped error chain to find the offending path/object ID within the snapshot.","Repair the repository (kopia repository repair / restore from the affected blobs) or delete/recreate the damaged snapshot.","Set OnDirectoryReadFailure to snapshotfs.RewriteAsStub(rep) so unreadable directories are stubbed instead of failing the entire snapshot rewrite.","Retry after resolving transient storage/network issues; the rewrite cache avoids reprocessing unchanged subtrees."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify snapshot root object exists before rewriting\nif _, err := rep.OpenObject(ctx, man.RootEntry.ObjectID); err != nil {\n    return fmt.Errorf(\"snapshot %d root object unreadable: %w\", man.ID, err)\n}","typeGuard":null,"tryCatchPattern":"changed, err := rw.RewriteSnapshotManifest(ctx, man, comp)\nif err != nil {\n    log.Printf(\"snapshot %d rewrite failed: %+v\", man.ID, err) // print full chain\n    // decide: skip snapshot, stub it, or abort\n    return false, nil\n}","preventionTips":["Set OnDirectoryReadFailure to RewriteAsStub to keep going past damaged directories.","Run kopia repository verify on snapshots before maintenance rewrites.","Process snapshots one at a time so one bad snapshot doesn't abort a batch.","Log the full error chain (%+v with pkg/errors) to locate the failing subtree."],"tags":["kopia","snapshot","rewrite","error-wrapping"],"backgroundTag":"file-read-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"}