{"record":{"id":"769f5295e1f7c539","repo":"anomalyco/sst","slug":"error-walking-target-directory-during-cleanup-w","errorCode":null,"errorMessage":"error walking target directory during cleanup: %w","messagePattern":"error walking target directory during cleanup: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/build.go","lineNumber":1084,"sourceCode":"\t\t\tif ext == \".pyo\" || fileName == \".DS_Store\" {\n\t\t\t\tos.Remove(path)\n\t\t\t}\n\t\t}\n\n\t\t// Remove test directories\n\t\tif info.IsDir() {\n\t\t\tdirName := info.Name()\n\t\t\tif dirName == \"SelfTest\" || dirName == \"tests\" || dirName == \"test\" {\n\t\t\t\tos.RemoveAll(path)\n\t\t\t\treturn filepath.SkipDir\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error walking target directory during cleanup: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// getWorkspacePackageNames returns workspace package names from pyproject.toml\nfunc getWorkspacePackageNames(projectInfo *projectInfo) []string {\n\tvar packages []string\n\n\t// Add the main package name\n\tif projectInfo.PyprojectPath != \"\" {\n\t\tif config, err := parsePyprojectToml(projectInfo.PyprojectPath); err == nil {\n\t\t\tif config.Project.Name != \"\" {\n\t\t\t\tpackages = append(packages, config.Project.Name)\n\t\t\t} else if config.Tool.Poetry.Name != \"\" {\n\t\t\t\tpackages = append(packages, config.Tool.Poetry.Name)\n\t\t\t}\n","sourceCodeStart":1066,"sourceCodeEnd":1102,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L1066-L1102","documentation":"cleanupInstalledDependencies post-processes the installed dependency directory (removing __pycache__/.pyo/.DS_Store files, test dirs, and boto3/botocore) using filepath.Walk. This error wraps any fatal error returned by the walk itself — in practice almost always the initial lstat/failure on the root targetDir (individual per-entry errors inside the walk callback are swallowed). The build cannot finish packaging the Python function without knowing whether the directory could be traversed.","triggerScenarios":"copySyncedDependencies calls cleanupInstalledDependencies(targetDir) where targetDir does not exist or is not readable (e.g. the uv/pip install step never created it, or the path was renamed/deleted between install and cleanup); filepath.Walk fails on the root and the wrapped error propagates out of copySyncedDependencies during deploy or the TestDeployBuilder_CleanupInstalledDependencies test.","commonSituations":"Racing processes/antivirus/IDE indexing locking or deleting files mid-walk; build cache (.sst) partially cleaned by another deploy; running deploys in parallel that share the same build directory; disk/permission problems on the build output directory.","solutions":["Run a clean rebuild (delete the .sst / build output directory for the function) so the target directory is recreated by the install step","Ensure no two deploy/dev processes run concurrently against the same project (parallel sst invocations share build dirs)","Check filesystem permissions and available disk space for the build output directory","Re-run the deploy — transient races during the walk are usually non-deterministic"],"exampleFix":"// before (root dir missing after failed install)\nsst deploy // fails: error walking target directory during cleanup: lstat .../.sst/build/...: no such file or directory\n// after\nrm -rf .sst && sst deploy  // install step recreates target dir before cleanup","handlingStrategy":"validation","validationCode":"// Go: before invoking the flow that ends in cleanup, ensure the target dir exists\nif info, err := os.Stat(buildOutputDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"build output dir %s missing; run the install step first\", buildOutputDir)\n}","typeGuard":null,"tryCatchPattern":"if err := cleanupInstalledDependencies(targetDir); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrNotExist) {\n        // target dir vanished: recreate via install step or skip cleanup\n    }\n    return err\n}","preventionTips":["Never delete or rename the build output directory while a deploy is in flight","Avoid parallel sst deploys sharing one .sst directory","Run cleanup only after the install step has confirmed success","Keep the build dir on a local filesystem (not an NFS/network mount prone to transient errors)"],"tags":["go","filesystem","build","python-runtime"],"backgroundTag":"directory-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}