{"record":{"id":"7b77db05711d92df","repo":"kopia/kopia","slug":"new-map","errorCode":null,"errorMessage":"new map","messagePattern":"new map","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"snapshot/snapshotfs/dir_rewriter.go","lineNumber":337,"sourceCode":"//\n//nolint:revive\nfunc RewriteRemove(ctx context.Context, parentPath string, entry *snapshot.DirEntry, err error) (*snapshot.DirEntry, error) {\n\treturn nil, nil\n}\n\n// NewDirRewriter creates a new directory rewriter.\nfunc NewDirRewriter(ctx context.Context, rep repo.RepositoryWriter, opts DirRewriterOptions) (*DirRewriter, error) {\n\tif opts.Parallel == 0 {\n\t\topts.Parallel = runtime.NumCPU()\n\t}\n\n\tif opts.OnDirectoryReadFailure == nil {\n\t\topts.OnDirectoryReadFailure = RewriteFail\n\t}\n\n\tcache, err := bigmap.NewMap(ctx)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"new map\")\n\t}\n\n\treturn &DirRewriter{\n\t\tws:    workshare.NewPool[*dirRewriterRequest](opts.Parallel - 1),\n\t\topts:  opts,\n\t\trep:   rep,\n\t\tcache: cache,\n\t}, nil\n}\n","sourceCodeStart":319,"sourceCodeEnd":347,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/snapshot/snapshotfs/dir_rewriter.go#L319-L347","documentation":"NewDirRewriter failed to create the bigmap.Map used as the rewriter's deduplication cache, so the DirRewriter cannot be constructed. bigmap backs the memoization that avoids reprocessing identical directory entries across snapshots.","triggerScenarios":"bigmap.NewMap(ctx) returns an error during NewDirRewriter — e.g. failures initializing in-memory/map storage or its underlying repository structures for the shared cache.","commonSituations":"Calling NewDirRewriter with a closed or unhealthy repository writer, context already canceled, resource exhaustion (memory limits), or an internal bigmap initialization bug in unusual environments.","solutions":["Check that the context passed to NewDirRewriter is not already canceled and the repository writer is open and healthy.","Inspect the inner bigmap error; ensure the process has adequate memory for the cache.","Retry after fixing repository connectivity; NewDirRewriter has no side effects on existing data, so retry is safe.","Report to Kopia if bigmap.NewMap fails on a healthy repository — this indicates an internal bug."],"exampleFix":"// before\nrw, err := snapshotfs.NewDirRewriter(canceledCtx, rep, opts) // ctx already canceled\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)\ndefer cancel()\nrw, err := snapshotfs.NewDirRewriter(ctx, rep, opts)","handlingStrategy":"validation","validationCode":"if rep == nil { return errors.New(\"rep must be a non-nil open RepositoryWriter\") }\nif err := ctx.Err(); err != nil { return err }","typeGuard":"func canCreateRewriter(ctx context.Context, rep repo.RepositoryWriter) bool {\n    return ctx.Err() == nil && rep != nil\n}","tryCatchPattern":"rw, err := snapshotfs.NewDirRewriter(ctx, rep, opts)\nif err != nil {\n    return fmt.Errorf(\"creating dir rewriter: %w\", err)\n}\ndefer rw.Close(ctx)","preventionTips":["Pass a live, uncanceled context to NewDirRewriter.","Always Close the rewriter to release the workshare pool and cache.","Ensure adequate memory for the bigmap cache on large snapshot sets.","Only construct the rewriter with an open RepositoryWriter."],"tags":["kopia","initialization","cache","bigmap"],"backgroundTag":"module-init-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"}