anomalyco/sst · error

failed to create destination file: %w

Error message

failed to create destination file: %w

What it means

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).

Source

Thrown at pkg/runtime/python/python.go:406

	slog.Info("function built", "functionID", input.FunctionID)
	return result, nil
}

// copyFile copies a single file from src to dst, creating parent directories as needed.
func copyFile(src, dst string) error {
	if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
		return fmt.Errorf("failed to create directory for %s: %w", dst, err)
	}

	srcFile, err := os.Open(src)
	if err != nil {
		return fmt.Errorf("failed to open source file: %w", err)
	}
	defer srcFile.Close()

	dstFile, err := os.Create(dst)
	if err != nil {
		return fmt.Errorf("failed to create destination file: %w", err)
	}
	defer dstFile.Close()

	if _, err := io.Copy(dstFile, srcFile); err != nil {
		return fmt.Errorf("failed to copy file contents: %w", err)
	}

	return nil
}

// skipContent skips __pycache__, .pyc files, and anything matching isIgnored.
func skipContent(relPath string, info os.FileInfo) bool {
	return isIgnored(relPath)
}

// skipBuildArtifacts skips only dirs that would break workspace package builds.
// Preserves metadata files (pyproject.toml, etc.) needed by uv pip install.
func skipBuildArtifacts(_ string, info os.FileInfo) bool {

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Create the destination parent directory (mkdir -p) and confirm the process has write permission to it
  2. Check the destination path is not a directory or a dangling symlink pointing outside the project
  3. Free disk space if the output volume is full
  4. Re-run deploy; if it persists, inspect the exact wrapped os error text (permission denied vs no such file) for the real cause

Example fix

// before
os.WriteFile(dst, data, 0644) // silently fails if parent dir missing
// after
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
	return err
}
os.WriteFile(dst, data, 0644)
Defensive patterns

Strategy: validation

Validate before calling

func canWrite(dst string) error {
	if fi, err := os.Stat(dst); err == nil && fi.IsDir() {
		return fmt.Errorf("destination is a directory: %s", dst)
	}
	return os.MkdirAll(filepath.Dir(dst), 0o755)
}

Try / catch

if err := sstBuild(); err != nil {
	if strings.Contains(err.Error(), "failed to create destination file") {
		// inspect wrapped os error: fix permissions or create parent dir, then retry
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/966d920ea6d355f6. Report an issue: GitHub.