{"record":{"id":"bc9a4c4ece05fd30","repo":"dagger/dagger","slug":"failed-to-copy-source-directory-w","errorCode":null,"errorMessage":"failed to copy source directory: %w","messagePattern":"failed to copy source directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/directory.go","lineNumber":2493,"sourceCode":"\t\t\t\t\tdestDirPath := filepath.Dir(copyDestPath)\n\t\t\t\t\texistsRoot := copyDest\n\t\t\t\t\tif parentRoot != \"\" {\n\t\t\t\t\t\texistsRoot = parentRoot\n\t\t\t\t\t}\n\t\t\t\t\tresolvedExistsPath, err := containerdfs.RootPath(existsRoot, destDirPath)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tif _, err := os.Lstat(resolvedExistsPath); err != nil {\n\t\t\t\t\t\terr = TrimErrPathPrefix(err, path.Join(mntedSrcPath, srcDir))\n\t\t\t\t\t\terr = TrimErrPathPrefix(err, existsRoot)\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif err := copier.Copy(ctx, layercopy.Mount{Root: mntedSrcPath, Mount: srcMnt}, srcPath, copyDestPath, opts); err != nil {\n\t\t\t\t\terr = TrimErrPathPrefix(err, path.Join(mntedSrcPath, srcDir))\n\t\t\t\t\terr = TrimErrPathPrefix(err, copyDest)\n\t\t\t\t\treturn fmt.Errorf(\"failed to copy source directory: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t}, mountRefAsReadOnly); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tusage, err = copier.Usage()\n\t\treturn err\n\t}); err != nil {\n\t\treturn err\n\t}\n\n\tref, err := newRef.CommitWithUsage(ctx, usage)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to commit copied directory: %w\", err)\n\t}\n\tdir.Snapshot.setValue(ref)","sourceCodeStart":2475,"sourceCodeEnd":2511,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/directory.go#L2475-L2511","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n.WithDirectory(\"/app\", src.Directory(\"srsc\"), nil) // typo\n// after\n.WithDirectory(\"/app\", src.Directory(\"src\"), nil)","handlingStrategy":"try-catch","validationCode":"// Check source path exists before copying\n_, err := client.Directory().WithDirectory(\"/\", src, nil).Directory(\"src\").Entries(ctx)\nif err != nil { return fmt.Errorf(\"source directory missing: %w\", err) }","typeGuard":null,"tryCatchPattern":"var perr *fs.PathError\nif errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrNotExist) {\n    return fmt.Errorf(\"source path %q not found in source directory\", srcPath)\n}\nif strings.Contains(err.Error(), \"no space left\") {\n    return fmt.Errorf(\"engine host out of disk; prune dagger cache\")\n}","preventionTips":["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."],"tags":["copy","filesystem","directory","enoent"],"backgroundTag":"copy-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}