dagger/dagger · error

failed to get parent directory path: %w

Error message

failed to get parent directory path: %w

What it means

This error wraps the underlying failure that occurred while resolving the parent directory's absolute path (`Directory.dir`) during lazy evaluation of a file sub-path. When a `File` is lazily constructed from a parent `Directory` plus a relative path (e.g. `directory.file(path)`), the engine must first evaluate the parent's path before it can stat/snapshot the file. Any error evaluating that path is re-wrapped with this message so the caller knows the failure happened in the parent-path resolution step.

Source

Thrown at core/file.go:573

		Filename:    lazy.Filename,
		Contents:    slices.Clone(lazy.Contents),
		Permissions: lazy.Permissions,
	})
}

func (lazy *FileSubfileLazy) Evaluate(ctx context.Context, file *File) error {
	return lazy.LazyState.Evaluate(ctx, "File.file", func(ctx context.Context) error {
		cache, err := dagql.EngineCache(ctx)
		if err != nil {
			return err
		}
		if err := cache.Evaluate(ctx, lazy.Parent); err != nil {
			return err
		}

		parentPath, err := lazy.Parent.Self().Dir.GetOrEval(ctx, lazy.Parent.Result)
		if err != nil {
			return fmt.Errorf("failed to get parent directory path: %w", err)
		}
		finalPath := filepath.Join(parentPath, lazy.Path)

		query, err := CurrentQuery(ctx)
		if err != nil {
			return err
		}
		srv, err := query.Server.Server(ctx)
		if err != nil {
			return err
		}

		info, err := lazy.Parent.Self().Stat(ctx, lazy.Parent, srv, lazy.Path, false)
		if err != nil {
			return err
		}
		if info.FileType == FileTypeDirectory {
			return notAFileError{fmt.Errorf("path %s is a directory, not a file", lazy.Path)}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Inspect the wrapped (`%w`) cause in the error chain — this message only indicates *where* it failed, the root cause is the inner error
  2. Verify the parent `Directory` argument is a valid, fully-evaluable directory (e.g. `dag.currentModule().workdir` or a valid `directory(name)`), not scratch
  3. Re-run with a fresh session/cache if a cache eviction or stale ref is suspected
  4. If the parent directory was produced by a failed pipeline step, fix that upstream step first

Example fix

// before: parent may be scratch/invalid
dir := client.Container().Rootfs()
file := dir.File("app/config.yaml")
// after: use a directory with a resolvable path
dir := client.Host().Directory("./config")
file := dir.File("app.yaml")
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure parent dir is concrete before deriving files
if dir == nil || dir.id() == "" { return errors.New("parent directory not initialized") }

Try / catch

try {
  const file = dir.file(path);
} catch (e) {
  if (String(e).includes("failed to get parent directory path")) {
    // inspect e.cause / wrapped error for the root cause; rebuild parent dir
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `Directory.file(path)` (or `file()` on a subdirectory) where evaluating the parent directory's `Dir` field fails — e.g. the parent directory is a lazy/remote result whose path resolution errored, the parent is a scratch/ephemeral directory with no path, or an underlying cached evaluation returned an error.

Common situations: Building files from directories that came from remote sources (git, image layers) where the underlying evaluation failed; using a directory whose backing cache record was evicted; chained `directory(name).file(...)` calls where the intermediate directory name was invalid.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/e4825df94a35a154. Report an issue: GitHub.