{"record":{"id":"c377426f772aefa8","repo":"anomalyco/sst","slug":"failed-to-copy-s-to-s-w-c37742","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/python.go","lineNumber":341,"sourceCode":"\t// Copy/update changed files\n\tfor relPath, sourceInfo := range sourceFiles {\n\t\tsourcePath := filepath.Join(srcDir, relPath)\n\t\tartifactPath := filepath.Join(destDir, relPath)\n\n\t\tneedsCopy := true\n\t\tif artifactInfo, exists := artifactFiles[relPath]; exists {\n\t\t\tif !sourceInfo.ModTime().After(artifactInfo.ModTime()) {\n\t\t\t\tneedsCopy = false\n\t\t\t}\n\t\t}\n\n\t\tif needsCopy {\n\t\t\tif err := os.MkdirAll(filepath.Dir(artifactPath), 0755); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create directory for %s: %v\", artifactPath, err)\n\t\t\t}\n\n\t\t\tif err := copyFile(sourcePath, artifactPath); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to copy %s to %s: %w\", sourcePath, artifactPath, err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// flattenSrcLayout removes the \"src/pkg\" segment from paths that follow the\n// PEP 517 src-layout convention (e.g., \"pkg/src/pkg/module\" -> \"pkg/module\").\n// Only flattens when the directory after \"src\" matches the directory before it.\nfunc flattenSrcLayout(filePath string) string {\n\tparts := strings.Split(filePath, \"/\")\n\tif len(parts) < 3 {\n\t\treturn filePath\n\t}\n\tfor i := 0; i < len(parts)-1; i++ {\n\t\tif parts[i] == \"src\" && i > 0 && i+1 < len(parts) && parts[i-1] == parts[i+1] {\n\t\t\tflattened := append([]string{}, parts[:i]...)","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/python.go#L323-L359","documentation":"Raised in syncPythonFiles (pkg/runtime/python/python.go:341) when copyFile fails while syncing a changed/new .py file from source into the artifact directory. copyFile wraps its own failures (mkdir, open source, create dest, io.Copy), so the cause chain tells you which low-level step failed — most often the source file was deleted mid-sync or the destination is unwritable.","triggerScenarios":"Source file deleted between the walk scan and the copy (racing editor/git operation); destination file locked or read-only; MkdirAll inside copyFile failing (disk full, permissions); io.Copy I/O error.","commonSituations":"Saving/deleting files rapidly during `sst dev` in workspace-layout Python projects; antivirus/indexers holding the destination file on Windows; read-only artifact dirs from container-built artifacts.","solutions":["Read the wrapped cause: 'failed to open source file' means the source vanished — re-save/recreate the file or restart dev so the walk rescan picks current state; 'failed to create destination file'/'create directory' means fix artifact permissions or disk space","Retry the operation — transient races usually resolve on the next sync trigger","Normalize the environment: stop dev, remove the artifact dir, restart to force a clean full sync"],"exampleFix":"// before\nfailed to copy handlers/user.py to .sst/artifacts/handlers/user.py: failed to open source file: no such file or directory\n// after (recreate or restore the file, then)\ngit checkout -- handlers/user.py\nsst dev","handlingStrategy":"retry","validationCode":"// confirm source file still exists just before copy\nif _, err := os.Stat(sourcePath); err != nil {\n    return fmt.Errorf(\"source vanished before copy: %s\", sourcePath)\n}","typeGuard":null,"tryCatchPattern":"if err := copyFile(sourcePath, artifactPath); err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        // file deleted mid-sync: rescan and retry once\n        return resyncAndRetry(sourcePath, artifactPath)\n    }\n    if errors.Is(err, fs.ErrPermission) {\n        return fixPermsAndRetry(artifactPath)\n    }\n    return err\n}","preventionTips":["Let the watcher quiesce (single save) instead of rapid multi-file churn while dev syncs","Exclude .sst from AV/indexer real-time scanning on Windows","Keep artifact dirs user-writable","If a sync error appears right after deleting a file, restart dev to refresh the scan"],"tags":["filesystem","copy","sync","race","python"],"backgroundTag":"file-copy-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}