pulumi/pulumi · error

copy source directory: %w

Error message

copy source directory: %w

What it means

GenerateProject copies the PCL source tree (excluding Pulumi.yaml) into the output directory with aferoutil.CopyDir; any copy failure is wrapped as "copy source directory". Typical causes are unreadable source files or unwritable destination paths.

Source

Thrown at sdk/pcl/cmd/pulumi-language-pcl/main.go:594

	if err := os.WriteFile(filepath.Join(req.TargetDirectory, "Pulumi.yaml"), projectBytes, 0o600); err != nil {
		return nil, fmt.Errorf("write Pulumi.yaml: %w", err)
	}

	// If main is set the Main.yaml file should be in a subdirectory
	directory := req.TargetDirectory
	if project.Main != "" {
		directory = path.Join(directory, project.Main)
		err := os.MkdirAll(directory, 0o700)
		if err != nil {
			return nil, fmt.Errorf("create output directory: %w", err)
		}
	}

	filter := func(info os.FileInfo) bool {
		return info.Name() != "Pulumi.yaml"
	}
	if err := aferoutil.CopyDir(afero.NewOsFs(), req.SourceDirectory, directory, filter); err != nil {
		return nil, fmt.Errorf("copy source directory: %w", err)
	}

	// Only copy local dependencies that the program actually references.
	referencedPackages := map[string]bool{}
	for _, ref := range program.PackageReferences() {
		referencedPackages[ref.Name()] = true
	}
	for name, content := range req.LocalDependencies {
		if !referencedPackages[name] {
			continue
		}
		outPath := path.Join(directory, name+".pp")
		err := fsutil.CopyFile(outPath, content, nil)
		if err != nil {
			return nil, fmt.Errorf("copy local dependency: %w", err)
		}
	}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Verify all files in the source directory are readable by the current user.
  2. Ensure the destination directory exists and is writable.
  3. Check for problematic symlinks or special files in the source tree and exclude/repair them.

Example fix

// before
chmod 000 secrets.pp && pulumi convert --out ./out
// after
chmod 644 secrets.pp && pulumi convert --out ./out
Defensive patterns

Strategy: validation

Validate before calling

err := filepath.Walk(sourceDir, func(p string, info os.FileInfo, err error) error {
    if err != nil {
        return err
    }
    if info.Mode()&0o400 == 0 {
        return fmt.Errorf("unreadable file: %s", p)
    }
    return nil
})

Prevention

When it happens

Trigger: aferoutil.CopyDir(afero.NewOsFs(), req.SourceDirectory, directory, filter) returns an error.

Common situations: Source directory containing files without read permission; destination on a full or read-only volume; symlinks pointing outside the tree failing to resolve.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/f4309c2ec750b7f9. Report an issue: GitHub.