{"record":{"id":"4beb5b474e36ec27","repo":"anomalyco/sst","slug":"failed-to-create-directory-for-workspace-package","errorCode":null,"errorMessage":"failed to create directory for workspace package %s: %w","messagePattern":"failed to create directory for workspace package (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/build.go","lineNumber":715,"sourceCode":"\t\t\t// Already exists — just ensure pyproject.toml is present for uv pip install\n\t\t\tsrcPyproject := filepath.Join(fullPath, \"pyproject.toml\")\n\t\t\tdestPyproject := filepath.Join(destPath, \"pyproject.toml\")\n\t\t\tif _, err := os.Stat(srcPyproject); err == nil {\n\t\t\t\tif _, err := os.Stat(destPyproject); err != nil {\n\t\t\t\t\tdata, readErr := os.ReadFile(srcPyproject)\n\t\t\t\t\tif readErr != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"failed to read pyproject.toml for workspace package %s: %w\", pkgPath, readErr)\n\t\t\t\t\t}\n\t\t\t\t\tif err := os.WriteFile(destPyproject, data, 0644); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"failed to copy pyproject.toml for workspace package %s: %w\", pkgPath, err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create directory for workspace package %s: %w\", pkgPath, err)\n\t\t}\n\n\t\t// Preserve pyproject.toml and metadata for uv pip install\n\t\tif err := copyDir(fullPath, destPath, skipBuildArtifacts); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy workspace package %s: %w\", pkgPath, err)\n\t\t}\n\n\t}\n\n\treturn nil\n}\n\n// copySourceFilesSimple copies handler source files to the build output.\n// Workspace packages are installed via uv pip install separately.\nfunc copySourceFilesSimple(input *runtime.BuildInput, projectInfo *projectInfo) error {\n\tworkspaceDir := projectInfo.SourceRoot\n\tif projectInfo.PyprojectPath != \"\" {\n\t\tworkspaceDir = filepath.Dir(projectInfo.PyprojectPath)","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L697-L733","documentation":"During a container build, SST creates the destination directory tree for each relative-path workspace package from requirements.txt via os.MkdirAll before copying files. This error is returned when that MkdirAll fails. It wraps the OS error, typically permissions or an invalid path component (e.g. a file exists where a directory is expected).","triggerScenarios":"os.MkdirAll(filepath.Dir(destPath), 0755) fails in copyWorkspacePackagesForContainer when a component of destPath (inside input.Out()) exists as a regular file, or the output directory is not writable.","commonSituations":"Stale/corrupt .sst build output where a previous build left a file at a path now needed as a directory; running deploy as a different user than a previous build; workspace package path like `./pkg` colliding with an existing file in the output.","solutions":["Delete the stale build output (`rm -rf .sst` or the relevant .sst/platform output dir) and redeploy.","Inspect the wrapped ENOTDIR/EACCES error path; remove the file blocking the directory path.","Fix ownership/permissions on the output directory so the current user can create directories.","Verify the relative path in requirements.txt (e.g. `./core`) matches an actual directory in the workspace root."],"exampleFix":"// before\nError: failed to create directory for workspace package ./packages/core: mkdir /out/packages: not a directory\n// after\n$ rm -rf .sst   # removes stale file blocking the path\n$ sst deploy","handlingStrategy":"validation","validationCode":"// before deploy: ensure output paths are directories or absent\nfor (const rel of ['packages/core']) {\n  const dest = path.join(buildOut, rel);\n  if (fs.existsSync(dest) && !fs.statSync(dest).isDirectory()) throw new Error(`${dest} is a file; clean .sst`);\n}\nfs.accessSync(buildOut, fs.constants.W_OK);","typeGuard":"null","tryCatchPattern":"try {\n  await deploy();\n} catch (e) {\n  if (/failed to create directory for workspace package/.test(e.message)) {\n    fs.rmSync('.sst', { recursive: true, force: true });\n    await deploy();\n  } else throw e;\n}","preventionTips":["Delete stale .sst output after switching branches that change package layout","Use one OS user for all sst commands","Keep relative paths in requirements.txt (./pkg) pointing at real directories","Check write permissions on the workspace before deploying"],"tags":["filesystem","python","container-build","mkdir"],"backgroundTag":"mkdir-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}