anomalyco/sst · error
error walking target directory during cleanup: %w
Error message
error walking target directory during cleanup: %w
What it means
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.
Source
Thrown at pkg/runtime/python/build.go:1084
if ext == ".pyo" || fileName == ".DS_Store" {
os.Remove(path)
}
}
// Remove test directories
if info.IsDir() {
dirName := info.Name()
if dirName == "SelfTest" || dirName == "tests" || dirName == "test" {
os.RemoveAll(path)
return filepath.SkipDir
}
}
return nil
})
if err != nil {
return fmt.Errorf("error walking target directory during cleanup: %w", err)
}
return nil
}
// getWorkspacePackageNames returns workspace package names from pyproject.toml
func getWorkspacePackageNames(projectInfo *projectInfo) []string {
var packages []string
// Add the main package name
if projectInfo.PyprojectPath != "" {
if config, err := parsePyprojectToml(projectInfo.PyprojectPath); err == nil {
if config.Project.Name != "" {
packages = append(packages, config.Project.Name)
} else if config.Tool.Poetry.Name != "" {
packages = append(packages, config.Tool.Poetry.Name)
}
View on GitHub (pinned to a0bd20f762)
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
Example fix
// before (root dir missing after failed install) sst deploy // fails: error walking target directory during cleanup: lstat .../.sst/build/...: no such file or directory // after rm -rf .sst && sst deploy // install step recreates target dir before cleanup
Defensive patterns
Strategy: validation
Validate before calling
// Go: before invoking the flow that ends in cleanup, ensure the target dir exists
if info, err := os.Stat(buildOutputDir); err != nil || !info.IsDir() {
return fmt.Errorf("build output dir %s missing; run the install step first", buildOutputDir)
} Try / catch
if err := cleanupInstalledDependencies(targetDir); err != nil {
var pe *fs.PathError
if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrNotExist) {
// target dir vanished: recreate via install step or skip cleanup
}
return err
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to read source directory: %w
- failed to create destination file: %w
- failed to copy file contents: %w
- failed to create output directory: %w
- failed to open source binary: %w
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/769f5295e1f7c539.
Report an issue: GitHub.