{"record":{"id":"966d920ea6d355f6","repo":"anomalyco/sst","slug":"failed-to-create-destination-file-w","errorCode":null,"errorMessage":"failed to create destination file: %w","messagePattern":"failed to create destination file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/python.go","lineNumber":406,"sourceCode":"\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\n\treturn nil\n}\n\n// skipContent skips __pycache__, .pyc files, and anything matching isIgnored.\nfunc skipContent(relPath string, info os.FileInfo) bool {\n\treturn isIgnored(relPath)\n}\n\n// skipBuildArtifacts skips only dirs that would break workspace package builds.\n// Preserves metadata files (pyproject.toml, etc.) needed by uv pip install.\nfunc skipBuildArtifacts(_ string, info os.FileInfo) bool {","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/python.go#L388-L424","documentation":"copyFile in the Python runtime wraps os.Create(dst) failures with this message. os.Create fails when the destination path cannot be opened for writing — the parent directory doesn't exist, permissions deny write, or the destination is a directory. The library throws it while assembling the Python build/bundle (Dockerfile generation, package flattening, dependency copying, and dev sync all funnel through copyFile).","triggerScenarios":"os.Create(dst) returns an error during any copyFile call: destination parent directory missing (e.g. flattenPackageToRoot or copyDependencyPackages targeting a non-existent bundle dir), destination is actually a directory, or the process lacks write permission on the destination path. Callers include ensureDockerfile, flattenPackageToRoot, copySourceFilesSimple, copyDependencyPackages, Run, and syncPythonFiles.","commonSituations":"A sst.config.ts sets a custom build output path that doesn't exist or is read-only; running in a container as a non-root user without write access to the bundle directory; a stale symlink or a directory named like the expected destination file; disk full on the volume holding .sst output.","solutions":["Create the destination parent directory (mkdir -p) and confirm the process has write permission to it","Check the destination path is not a directory or a dangling symlink pointing outside the project","Free disk space if the output volume is full","Re-run deploy; if it persists, inspect the exact wrapped os error text (permission denied vs no such file) for the real cause"],"exampleFix":"// before\nos.WriteFile(dst, data, 0644) // silently fails if parent dir missing\n// after\nif err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {\n\treturn err\n}\nos.WriteFile(dst, data, 0644)","handlingStrategy":"validation","validationCode":"func canWrite(dst string) error {\n\tif fi, err := os.Stat(dst); err == nil && fi.IsDir() {\n\t\treturn fmt.Errorf(\"destination is a directory: %s\", dst)\n\t}\n\treturn os.MkdirAll(filepath.Dir(dst), 0o755)\n}","typeGuard":null,"tryCatchPattern":"if err := sstBuild(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to create destination file\") {\n\t\t// inspect wrapped os error: fix permissions or create parent dir, then retry\n\t}\n}","preventionTips":["Always MkdirAll the destination parent before copying","Run deploys as a user with write access to the project/.sst directory","Monitor disk space on the build volume","Check destination paths aren't directories or dangling symlinks"],"tags":["go","filesystem","io","build"],"backgroundTag":"destination-file-create-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}