{"record":{"id":"bc62fe83e94db433","repo":"anomalyco/sst","slug":"failed-to-create-directory-for-s-v","errorCode":null,"errorMessage":"failed to create directory for %s: %v","messagePattern":"failed to create directory for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/python.go","lineNumber":337,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\n\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","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/python.go#L319-L355","documentation":"Raised in syncPythonFiles (pkg/runtime/python/python.go:337) when os.MkdirAll cannot create the parent directory of an artifact .py file before copying an updated/new source file. Indicates the artifact tree cannot be written: permissions, a file where a directory is expected, or a read-only mount.","triggerScenarios":"Artifact dir read-only or owned by root (built in Docker); an existing regular file occupies the directory path being created (e.g. a file named like a package dir); disk full; ENAMETOOLONG for deeply nested workspace paths.","commonSituations":"Workspace-layout (package/src/package) Python projects where CI containers created root-owned artifacts; a repo file named `src` colliding with a needed directory; full disk on long dev sessions.","solutions":["Check the wrapped error: if permission denied, `sudo chown -R $(whoami) .sst` and rerun; if 'file exists', remove/rename the conflicting file so the directory can be created","Free disk space if the error is 'no space left on device'","Rebuild artifacts from scratch: stop dev, `rm -rf` the function artifact dir, restart `sst dev`"],"exampleFix":"// before\nfailed to create directory for .sst/artifacts/api/src/api: mkdir: not a directory\n// after\nmv .sst/artifacts/api/src .sst/artifacts/api/src.bak  # file shadowing dir\nsst dev","handlingStrategy":"validation","validationCode":"// ensure no file shadows a needed directory and dest is writable\ndir := filepath.Dir(artifactPath)\nif fi, err := os.Lstat(dir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s is a file where a directory is required\", dir)\n}\nif err := os.MkdirAll(dir, 0755); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := syncPythonFiles(src, dst); err != nil {\n    if strings.Contains(err.Error(), \"failed to create directory\") {\n        os.RemoveAll(dst) // rebuild artifacts cleanly after fixing perms/space\n        return syncPythonFiles(src, dst)\n    }\n    return err\n}","preventionTips":["Don't name repo files after package directories that will be created in artifacts","Watch free disk space during long dev sessions","chown .sst after Docker-based builds","Keep paths reasonably short in deeply nested monorepos (ENAMETOOLONG)"],"tags":["filesystem","mkdir","permissions","sync","python"],"backgroundTag":"permission-denied","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}