{"record":{"id":"b564964363e369fe","repo":"anomalyco/sst","slug":"failed-to-create-directory-for-s-w","errorCode":null,"errorMessage":"failed to create directory for %s: %w","messagePattern":"failed to create directory for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/python.go","lineNumber":395,"sourceCode":"}\n\nfunc (r *PythonRuntime) CreateBuildAsset(ctx context.Context, input *runtime.BuildInput) (*runtime.BuildOutput, error) {\n\tworkingDir := path.ResolveRootDir(input.CfgPath)\n\n\tresult, err := buildDeploy(ctx, input, filepath.Join(workingDir, \".sst/cache/deploy\"), workingDir)\n\tif err != nil {\n\t\tslog.Error(\"build failed\", \"functionID\", input.FunctionID, \"error\", err)\n\t\treturn nil, err\n\t}\n\n\tslog.Info(\"function built\", \"functionID\", input.FunctionID)\n\treturn result, nil\n}\n\n// copyFile copies a single file from src to dst, creating parent directories as needed.\nfunc copyFile(src, dst string) error {\n\tif err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create directory for %s: %w\", dst, err)\n\t}\n\n\tsrcFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\t}\n\tdefer srcFile.Close()\n\n\tdstFile, err := os.Create(dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err := io.Copy(dstFile, srcFile); err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file contents: %w\", err)\n\t}\n","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/python.go#L377-L413","documentation":"Raised in copyFile (pkg/runtime/python/python.go:395) when os.MkdirAll cannot create the destination's parent directory. copyFile is used by the lambda-bridge copy, workspace flattening, source copying, and dependency-package copies, so this error surfaces wherever SST stages Python files into artifact directories. Common causes: permissions, a file existing where a directory is needed, or read-only/invalid paths.","triggerScenarios":"Artifact or target dir owned by root from container builds; a regular file exists at the directory path; read-only volume; path too long; disk full during Run's bridge copy or flattenWorkspaceLayouts.","commonSituations":"Root-owned .sst after Docker/CI builds; a repo file named like a package directory colliding during flattening; moving the project across filesystems with restrictive mounts.","solutions":["Read the wrapped cause; if permission denied run `sudo chown -R $(whoami) .sst` (and the platform dir if needed), then rerun","If the error is 'not a directory'/'file exists', remove or rename the conflicting file at that path","Verify disk space and that the destination isn't on a read-only mount; then restart the build"],"exampleFix":"// before\nfailed to create directory for .sst/artifacts/pkg/mod.py: mkdir .sst/artifacts/pkg: permission denied\n// after\nsudo chown -R $(whoami) .sst\nsst deploy","handlingStrategy":"try-catch","validationCode":"// ensure destination parent path is not shadowed by a file\ndir := filepath.Dir(dst)\nif fi, err := os.Lstat(dir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"cannot create %s: exists as file\", dir)\n}\nif err := os.MkdirAll(dir, 0755); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := copyFile(src, dst); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && (errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrExist)) {\n        prepareDestDir(dst) // chown/remove shadowing file, then mkdir\n        return copyFile(src, dst)\n    }\n    return err\n}","preventionTips":["chown .sst back to your user after any container/root build","Verify disk space before large deploys","Avoid files in the repo whose names collide with artifact directory paths","Ensure destination volumes are mounted read-write"],"tags":["filesystem","mkdir","permissions","copy","python"],"backgroundTag":"permission-denied","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}