dagger/dagger · error
failed to copy source directory: %w
Error message
failed to copy source directory: %w
What it means
The core copy step: for each resolved source path, copier.Copy copies from the mounted source snapshot into the new destination snapshot (honoring include/exclude filters, ownership, permissions). On failure, path prefixes are trimmed for readability and the error is wrapped as 'failed to copy source directory'. This covers any underlying filesystem error during the copy (missing source path, permission denied, ENOSPC, cross-device issues).
Source
Thrown at core/directory.go:2493
destDirPath := filepath.Dir(copyDestPath)
existsRoot := copyDest
if parentRoot != "" {
existsRoot = parentRoot
}
resolvedExistsPath, err := containerdfs.RootPath(existsRoot, destDirPath)
if err != nil {
return err
}
if _, err := os.Lstat(resolvedExistsPath); err != nil {
err = TrimErrPathPrefix(err, path.Join(mntedSrcPath, srcDir))
err = TrimErrPathPrefix(err, existsRoot)
return err
}
}
if err := copier.Copy(ctx, layercopy.Mount{Root: mntedSrcPath, Mount: srcMnt}, srcPath, copyDestPath, opts); err != nil {
err = TrimErrPathPrefix(err, path.Join(mntedSrcPath, srcDir))
err = TrimErrPathPrefix(err, copyDest)
return fmt.Errorf("failed to copy source directory: %w", err)
}
}
return nil
}, mountRefAsReadOnly); err != nil {
return err
}
usage, err = copier.Usage()
return err
}); err != nil {
return err
}
ref, err := newRef.CommitWithUsage(ctx, usage)
if err != nil {
return fmt.Errorf("failed to commit copied directory: %w", err)
}
dir.Snapshot.setValue(ref)View on GitHub (pinned to 82ba2681db)
Solutions
- Check the wrapped inner error: ENOENT means fix the source path; ENOSPC means free disk space on the engine host.
- Verify include/exclude filters don't accidentally exclude all files being copied.
- Set createDestPath (or ensure the destination parent exists) and confirm the source directory ref was built from the expected directory.
Example fix
// before
.WithDirectory("/app", src.Directory("srsc"), nil) // typo
// after
.WithDirectory("/app", src.Directory("src"), nil) Defensive patterns
Strategy: try-catch
Validate before calling
// Check source path exists before copying
_, err := client.Directory().WithDirectory("/", src, nil).Directory("src").Entries(ctx)
if err != nil { return fmt.Errorf("source directory missing: %w", err) } Try / catch
var perr *fs.PathError
if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {
return fmt.Errorf("source path %q not found in source directory", srcPath)
}
if strings.Contains(err.Error(), "no space left") {
return fmt.Errorf("engine host out of disk; prune dagger cache")
} Prevention
- Verify source paths and wildcards resolve to files (print Entries() during debugging).
- Ensure include/exclude filters don't exclude everything you intend to copy.
- Monitor engine disk usage; ENOSPC commonly surfaces here.
When it happens
Trigger: Directory.withDirectory / withDirectoryDockerfileCompat where the source path doesn't exist in the source snapshot (unless createDestPath checks pass differently), filters match nothing copyable, the destination file conflicts, or the host filesystem errors mid-copy.
Common situations: Typos in source path, copying with include patterns that exclude everything, no space left on device, permission bits preventing chown, or wildcard patterns resolving to zero paths followed by an invalid copy.
Related errors
- copy changed paths: %w
- cannot copy to non-directory: %s
- copy changed paths: %w
- stage before delta: %w
- stage after delta: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/bc9a4c4ece05fd30.
Report an issue: GitHub.