{"record":{"id":"5fb12e0f835d4684","repo":"anomalyco/sst","slug":"failed-to-create-output-directory-w","errorCode":null,"errorMessage":"failed to create output directory: %w","messagePattern":"failed to create output directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/build.go","lineNumber":529,"sourceCode":"\t\tif info.IsDir() {\n\t\t\treturn nil\n\t\t}\n\n\t\text := filepath.Ext(path)\n\t\tif ext == \".py\" || ext == \".pyi\" || info.Name() == \"py.typed\" {\n\t\t\tpythonFiles = append(pythonFiles, path)\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to walk extracted directory: %w\", err)\n\t}\n\n\t// Create output directory\n\tif err := os.MkdirAll(outputDir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create output directory: %w\", err)\n\t}\n\n\tfor _, srcFile := range pythonFiles {\n\t\trelPath, _ := filepath.Rel(extractedDir, srcFile)\n\t\tdestFile := filepath.Join(outputDir, relPath)\n\n\t\tif err := copyFile(srcFile, destFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy %s to %s: %w\", srcFile, destFile, err)\n\t\t}\n\t}\n\n\t// Clean up the extracted directory\n\tos.RemoveAll(extractedDir)\n\n\treturn nil\n}\n\nfunc installDependenciesForBuild(ctx context.Context, input *runtime.BuildInput, projectInfo *projectInfo) error {","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L511-L547","documentation":"flattenPackageToRoot copies all files out of an extracted Python package into a single flat output directory. Before copying it creates outputDir with os.MkdirAll; if that fails (bad path, permission denied, path is a file, disk full) the walk/copy is aborted and this wrapped error is returned up through moveExtractedPackage.","triggerScenarios":"os.MkdirAll(outputDir, 0755) fails because outputDir's parent doesn't exist and can't be created, a component of the path is a regular file, the process lacks write permission on the parent, or the filesystem is read-only/full.","commonSituations":"Building a Python Lambda into an output dir whose parent was removed or is read-only (e.g. .sst build cache dir owned by root after running with sudo); outputDir collides with an existing file; building on a mounted read-only volume or a full disk.","solutions":["Check permissions/ownership on the output directory's parent path (chown/chmod, avoid running some builds with sudo which leaves root-owned .sst dirs)","Verify no file exists at the outputDir path; delete or rename it","Ensure the parent directory exists and the volume is writable (df -h, mount flags)","Free disk space if the filesystem is full"],"exampleFix":"// before\nif err := os.MkdirAll(outputDir, 0755); err != nil {\n\treturn fmt.Errorf(\"failed to create output directory: %w\", err)\n}\n// after (clear a file blocking the path, then retry)\nif fi, statErr := os.Stat(outputDir); statErr == nil && !fi.IsDir() {\n\tos.Remove(outputDir)\n}\nif err := os.MkdirAll(outputDir, 0755); err != nil {\n\treturn fmt.Errorf(\"failed to create output directory %s: %w\", outputDir, err)\n}","handlingStrategy":"validation","validationCode":"import os\nif fi := statIfExists(outputDir); fi != nil && !fi.IsDir() { t.Fatalf(\"%s is a file\", outputDir) }\nif fi, err := os.Stat(filepath.Dir(outputDir)); err != nil || !fi.IsDir() { t.Fatalf(\"parent of %s missing\", outputDir) }\nif unix.Access(filepath.Dir(outputDir), unix.W_OK) != nil { t.Fatalf(\"no write permission on %s\", filepath.Dir(outputDir)) }","typeGuard":"func isWritableDir(path string) bool {\n\tfi, err := os.Stat(path)\n\tif err == nil && !fi.IsDir() {\n\t\treturn false\n\t}\n\tf, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o755)\n\tif err != nil {\n\t\treturn false\n\t}\n\tf.Close()\n\treturn true\n}","tryCatchPattern":"if err := runFlatten(); err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {\n\t\t// fix ownership: sudo chown -R $(id -u) <parent dir>\n\t}\n\treturn err\n}","preventionTips":["Don't run builds with sudo; if you did, chown the .sst directory back to your user","Ensure the build output parent exists and is on a writable (non read-only) volume","Check df -h before large builds; ENOSPC surfaces as path errors","Verify nothing (a stray file) occupies the output path before building"],"tags":["filesystem","io","python","build"],"backgroundTag":"mkdir-failed-permission-denied","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}