anomalyco/sst · error

failed to copy file contents: %w

Error message

failed to copy file contents: %w

What it means

copyFile wraps io.Copy failures (reading src and writing dst streams) with this message. After both files open successfully, the actual byte transfer failed — typically a read error on the source or a write error (disk full, I/O error) on the destination. It is thrown from the same Python runtime copy helper used across build, packaging, and dev sync.

Source

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

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 {
	if !info.IsDir() {
		return false
	}
	name := info.Name()
	return name == "__pycache__" || name == ".venv" || name == "node_modules" || name == ".git"

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Check free disk space and quota on the output volume
  2. Re-run the deploy/dev sync — transient FS races often resolve on retry
  3. Verify the source file is a regular readable file (not a fifo/device/symlink to something unreadable)
  4. Inspect the wrapped error text to distinguish read vs write side failure

Example fix

// before
_, err = io.Copy(dstFile, srcFile)
// after
if fi, statErr := os.Stat(src); statErr == nil && !fi.Mode().IsRegular() {
	return fmt.Errorf("skipping non-regular file: %s", src)
}
_, err = io.Copy(dstFile, srcFile)
Defensive patterns

Strategy: retry

Validate before calling

func regularReadable(path string) error {
	fi, err := os.Stat(path)
	if err != nil {
		return err
	}
	if !fi.Mode().IsRegular() {
		return fmt.Errorf("not a regular file: %s", path)
	}
	f, err := os.Open(path)
	if err != nil {
		return err
	}
	return f.Close()
}

Try / catch

if err := sstBuild(); err != nil {
	if strings.Contains(err.Error(), "failed to copy file contents") {
		// free disk space / re-run; transient FS races typically clear on retry
	}
}

Prevention

When it happens

Trigger: io.Copy(dstFile, srcFile) errors during copyFile: source file unreadable mid-read (removed, changed permissions, device error) or destination write fails (disk full, quota, I/O error). Reached from ensureDockerfile, flattenPackageToRoot, copySourceFilesSimple, copyDependencyPackages, Run, and syncPythonFiles.

Common situations: Source file deleted or truncated by a watcher/build race while dev sync is copying; filesystem quota or full disk on the build output volume; networked filesystem (NFS/EFS) hiccup; source is a special file (device/fifo) that errors on read.

Related errors


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