anomalyco/sst · error

failed to copy file %s: %w

Error message

failed to copy file %s: %w

What it means

While enumerating root-level .py files in the workspace, copySourceFilesSimple copies each one into the build output with copyFile. This error is returned for a specific .py file that fails to copy; the message names the file and the wrapped OS error gives the cause (unreadable source or unwritable destination).

Source

Thrown at pkg/runtime/python/build.go:787

				}
				copied = true
				break
			}
		}
		if !copied {
			// Handler path fully resolved by workspaceDir — root .py files will be copied below
		}
	}

	// Also copy root-level .py files
	entries, err := os.ReadDir(workspaceDir)
	if err != nil {
		return fmt.Errorf("failed to read workspace directory: %w", err)
	}
	for _, entry := range entries {
		if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".py") {
			if err := copyFile(filepath.Join(workspaceDir, entry.Name()), filepath.Join(outputBase, entry.Name())); err != nil {
				return fmt.Errorf("failed to copy file %s: %w", entry.Name(), err)
			}
		}
	}

	return nil
}

// copySyncedDependencies installs dependencies with correct platform targeting
func copySyncedDependencies(ctx context.Context, input *runtime.BuildInput, projectInfo *projectInfo, architecture string) error {
	requirementsPath := filepath.Join(input.Out(), "requirements.txt")

	if _, err := os.Stat(requirementsPath); os.IsNotExist(err) {
		slog.Warn("requirements.txt not found, skipping dependency installation", "path", requirementsPath)
		return nil
	}

	workspaceRoot := findWorkspaceRoot(projectInfo)

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Fix permissions on the named file: `chmod u+r <file>.py`.
  2. Remove the conflicting directory/file at the destination in the build output (`rm -rf .sst`).
  3. Free disk space if the wrapped error is ENOSPC.
  4. Check the workspace is not mounted read-only and the current user has write access to the output dir.

Example fix

// before
Error: failed to copy source files: failed to copy file utils.py: permission denied
// after
$ chmod u+r utils.py
$ rm -rf .sst
$ sst deploy
Defensive patterns

Strategy: try-catch

Validate before calling

for (const f of fs.readdirSync(wsDir).filter(f => f.endsWith('.py'))) {
  fs.accessSync(path.join(wsDir, f), fs.constants.R_OK);
  const dest = path.join(buildOut, f);
  if (fs.existsSync(dest) && fs.statSync(dest).isDirectory()) throw new Error(`dest collision: ${dest}`);
}

Type guard

null

Try / catch

try {
  await deploy();
} catch (e) {
  if (/failed to copy file \S+\.py/.test(e.message)) {
    fs.chmodSync(e.message.match(/file (\S+\.py)/)?.[1] ?? '.', 0o644); // restore readability
    await deploy();
  } else throw e;
}

Prevention

When it happens

Trigger: copyFile(filepath.Join(workspaceDir, entry.Name()), filepath.Join(outputBase, entry.Name())) fails — the .py file is unreadable, the destination exists as a directory, or the output volume is full/read-only.

Common situations: A root .py file with restrictive permissions; an output path colliding with a directory of the same name from a prior build; disk quota exceeded on CI; read-only mounted workspace.

Related errors


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