kopia/kopia · error

unable to create dir rewriter

Error message

unable to create dir rewriter

What it means

Wraps a failure from snapshotfs.NewDirRewriter, which builds the object used to rewrite directory entries inside snapshots. The error means the rewriter could not even be constructed, before any snapshot was processed. The original cause explains which internal prerequisite failed.

Solutions

  1. Check the wrapped cause for the invalid option value
  2. Use a valid --parallel value (positive integer)
  3. Use a supported --invalid-directory-handling value (e.g. fail, skip-all)
  4. Re-run with default flags to confirm the command works without overrides

Example fix

// before
kopia snapshot fix remove-invalid-files --parallel 0
// after
kopia snapshot fix remove-invalid-files --parallel 4
Defensive patterns

Strategy: validation

Validate before calling

if parallel <= 0 {
	return errors.New("--parallel must be a positive integer")
}
if !validInvalidDirHandling(handling) {
	return errors.Errorf("unsupported --invalid-directory-handling %v", handling)
}

Try / catch

rw, err := snapshotfs.NewDirRewriter(ctx, rep, opts)
if err != nil {
	return errors.Wrap(err, "dir rewriter setup failed")
}
defer rw.Close(ctx)

Prevention

When it happens

Trigger: Running `kopia snapshot fix <command>` (e.g. remove-invalid-files) with an invalid --parallel value or an invalid --invalid-directory-handling setting passed into DirRewriterOptions.

Common situations: Passing a non-positive or unparsable --parallel count, or an unsupported --invalid-directory-handling enum value.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/ee2977266702812f. Report an issue: GitHub.

Appendix: source

Thrown at cli/command_snapshot_fix.go:74

	default:
		return snapshotfs.RewriteFail
	case invalidEntryStub:
		return snapshotfs.RewriteAsStub(rep)
	case invalidEntryRemove:
		return snapshotfs.RewriteRemove
	case invalidEntryKeep:
		return snapshotfs.RewriteKeep
	}
}

func (c *commonRewriteSnapshots) rewriteMatchingSnapshots(ctx context.Context, rep repo.RepositoryWriter, rewrite snapshotfs.RewriteDirEntryCallback) error {
	rw, err := snapshotfs.NewDirRewriter(ctx, rep, snapshotfs.DirRewriterOptions{
		Parallel:               c.parallel,
		RewriteEntry:           rewrite,
		OnDirectoryReadFailure: failedEntryCallback(rep, c.invalidDirHandling),
	})
	if err != nil {
		return errors.Wrap(err, "unable to create dir rewriter")
	}

	defer rw.Close(ctx)

	var updatedSnapshots int

	manifestIDs, err := c.listManifestIDs(ctx, rep)
	if err != nil {
		return err
	}

	manifests, err := snapshot.LoadSnapshots(ctx, rep, manifestIDs)
	if err != nil {
		return errors.Wrap(err, "error loading snapshots")
	}

	for _, mg := range snapshot.GroupBySource(manifests) {
		log(ctx).Infof("Processing snapshot %v", mg[0].Source)

View on GitHub (pinned to 82495e54b5)