benbjohnson/litestream · error

create parent directory: %w

Error message

create parent directory: %w

What it means

Wraps internal.MkdirAll failure in Replica.Restore while creating the parent directory of the restore output path. Fires when the output directory cannot be created (permissions, path conflict), so the restored database file has nowhere to be written.

Source

Thrown at replica.go:724

				info.Level, info.MinTXID, info.MaxTXID, info.Size, ltx.HeaderSize)
		}

		r.Logger().Debug("opening ltx file for restore", "level", info.Level, "min", info.MinTXID, "max", info.MaxTXID)

		rdrs = append(rdrs, internal.NewResumableReader(ctx, r.Client, info.Level, info.MinTXID, info.MaxTXID, info.Size, nil, r.Logger()))
	}

	if len(rdrs) == 0 {
		return fmt.Errorf("no matching backup files available")
	}

	// Create parent directory if it doesn't exist.
	var dirInfo os.FileInfo
	if db := r.DB(); db != nil {
		dirInfo = db.dirInfo
	}
	if err := internal.MkdirAll(filepath.Dir(opt.OutputPath), dirInfo); err != nil {
		return fmt.Errorf("create parent directory: %w", err)
	}

	// Output to temp file & atomically rename.
	tmpOutputPath := opt.OutputPath + ".tmp"
	r.Logger().Debug("compacting into database", "path", tmpOutputPath, "n", len(rdrs))
	defer func() { _ = os.Remove(tmpOutputPath) }()

	f, err := os.Create(tmpOutputPath)
	if err != nil {
		return fmt.Errorf("create temp database path: %w", err)
	}
	defer func() { _ = f.Close() }()

	pr, pw := io.Pipe()

	go func() {
		c, err := ltx.NewCompactor(pw, rdrs)
		if err != nil {

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check the output path for conflicts with existing files
  2. Create the directory manually or fix permissions
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at replica.go:724 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/a7c93ced1f1b23db. Report an issue: GitHub.