{"record":{"id":"a53fffe3b757fb49","repo":"anomalyco/sst","slug":"failed-to-copy-s-to-s-w","errorCode":null,"errorMessage":"failed to copy %s to %s: %w","messagePattern":"failed to copy (.+?) to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/build.go","lineNumber":537,"sourceCode":"\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to walk extracted directory: %w\", err)\n\t}\n\n\t// Create output directory\n\tif err := os.MkdirAll(outputDir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create output directory: %w\", err)\n\t}\n\n\tfor _, srcFile := range pythonFiles {\n\t\trelPath, _ := filepath.Rel(extractedDir, srcFile)\n\t\tdestFile := filepath.Join(outputDir, relPath)\n\n\t\tif err := copyFile(srcFile, destFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy %s to %s: %w\", srcFile, destFile, err)\n\t\t}\n\t}\n\n\t// Clean up the extracted directory\n\tos.RemoveAll(extractedDir)\n\n\treturn nil\n}\n\nfunc installDependenciesForBuild(ctx context.Context, input *runtime.BuildInput, projectInfo *projectInfo) error {\n\tif err := os.MkdirAll(input.Out(), 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create output directory: %w\", err)\n\t}\n\n\trequirementsFile := filepath.Join(input.Out(), \"requirements.txt\")\n\tif err := generateOrCopyRequirementsFile(ctx, projectInfo, requirementsFile); err != nil {\n\t\treturn fmt.Errorf(\"failed to generate requirements file: %w\", err)\n\t}","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L519-L555","documentation":"flattenPackageToRoot iterates every file found in the extracted package and copies it to the flat output directory with copyFile. Any per-file copy failure (missing source, unreadable file, missing destination directory, permission error) is wrapped with both source and destination paths so the offending file is identifiable.","triggerScenarios":"copyFile(srcFile, destFile) fails: srcFile disappeared or is unreadable (permissions, broken symlink), destFile's parent directory wasn't created, or the destination filesystem is full/read-only.","commonSituations":"A file inside the extracted wheel/archive is a dangling symlink or has restrictive modes; nested subdirectories whose parent dirs were never MkdirAll'd before copy; ENOSPC when copying a large dependency tree into the build output.","solutions":["Run the build again — transient issues (deleted temp files, races with other builds) often resolve; avoid running concurrent builds into the same output dir","Inspect the srcFile/destFile paths in the message and check permissions and existence of the file and its destination parent directory","Free disk space (ENOSPC shows up as copy failures)","If a specific archive file is consistently failing, reinstall/refresh the dependency or remove a broken symlink before building"],"exampleFix":"// before\nif err := copyFile(srcFile, destFile); err != nil {\n\treturn fmt.Errorf(\"failed to copy %s to %s: %w\", srcFile, destFile, err)\n}\n// after (ensure destination dir exists first)\nos.MkdirAll(filepath.Dir(destFile), 0755)\nif err := copyFile(srcFile, destFile); err != nil {\n\treturn fmt.Errorf(\"failed to copy %s to %s: %w\", srcFile, destFile, err)\n}","handlingStrategy":"try-catch","validationCode":"for _, f := range filesToCopy {\n\tif fi, err := os.Lstat(f); err != nil || !fi.Mode().IsRegular() {\n\t\t// skip or fix broken symlinks / unreadable files before copying\n\t}\n}\ndfOut, _ := exec.Command(\"df\", \"-h\", outputDir).Output() // ensure free space","typeGuard":"func isRegularReadable(path string) bool {\n\tfi, err := os.Stat(path)\n\treturn err == nil && fi.Mode().IsRegular() && unix.Access(path, unix.R_OK) == nil\n}","tryCatchPattern":"err := buildPython()\nvar pe *fs.PathError\nswitch {\ncase errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC):\n\tfreeDiskAndRetry()\ncase errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES):\n\tfixPerms(pe.Path)\n}","preventionTips":["Avoid running concurrent builds into the same output directory","Refresh/reinstall dependencies whose archives contain symlinks that may dangle","Keep free disk headroom for site-packages-sized copies","Check permissions of files extracted from archives (umask) before copying"],"tags":["filesystem","io","copy","python","build"],"backgroundTag":"file-copy-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}