anomalyco/sst · error

failed to open source file: %w

Error message

failed to open source file: %w

What it means

Raised in copyFile (pkg/runtime/python/python.go:400) when os.Open cannot read the source file being copied (bridge script, source .py, or dependency package file). Nearly always 'no such file or directory' because the file was deleted/renamed between the scan and copy, or 'permission denied' when the file is unreadable by the sst process.

Source

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

	result, err := buildDeploy(ctx, input, filepath.Join(workingDir, ".sst/cache/deploy"), workingDir)
	if err != nil {
		slog.Error("build failed", "functionID", input.FunctionID, "error", err)
		return nil, err
	}

	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 {

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Check the wrapped cause: if the named source file is gone, restore it (git checkout/re-save) or restart the sync so the file list is refreshed
  2. If permission denied, chmod/chown the source file so the sst process can read it
  3. If the missing file is the platform bridge, re-sync the platform (rebuild platform dist) so dist/python-runtime/index.py exists

Example fix

// before
failed to open source file: open api/src/api/mod.py: no such file or directory
// after
git checkout -- api/src/api/mod.py
sst dev
Defensive patterns

Strategy: try-catch

Validate before calling

// check source readable before copy
f, err := os.Open(src)
if err != nil { return fmt.Errorf("precheck failed for %s: %v", src, err) }
f.Close()

Try / catch

if err := copyFile(src, dst); err != nil {
    if errors.Is(err, fs.ErrNotExist) {
        restoreSource(src) // git checkout / resync, then retry
        return copyFile(src, dst)
    }
    if errors.Is(err, fs.ErrPermission) {
        return chmodAndRetry(src, dst)
    }
    return err
}

Prevention

When it happens

Trigger: Source .py deleted by editor/git right after the walk collected it; dependency package file removed by a concurrent uv install; platform dist/python-runtime/index.py missing when copying the lambda bridge; unreadable file modes from a foreign checkout.

Common situations: Rapid save/delete during `sst dev` in workspace-layout projects; incomplete dependency install leaving missing files; platform dir not synced (missing dist/python-runtime/index.py) when Run copies the bridge.

Related errors


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