pulumi/pulumi · error

stat %s: %w

Error message

stat %s: %w

What it means

Thrown when generating provider instructions (GetProgramDependencies flow) and os.Stat on the program's go.mod fails. The stat result is also needed later to preserve file permissions when rewriting go.mod, so failure is fatal.

Source

Thrown at sdk/go/pulumi-language-go/main.go:1701

		modules[modulePath] = dep.Path
		// The relative path used in the replace directive must start with `./` or `.\`.
		// https://go.dev/ref/mod#go-mod-file-replace
		start := "./"
		if runtime.GOOS == "windows" {
			start = ".\\"
		}
		if !strings.HasPrefix(dep.Path, start) {
			modules[modulePath] = start + dep.Path
		}
		fmt.Fprintf(&imports, "    \"%s\"\n", codegen.ExtractImportBasePath(pkg.Reference()))
	}
	instructions += imports.String()
	instructions += "  )\n"

	gomodFilepath := filepath.Join(req.Info.ProgramDirectory, "go.mod")
	stat, err := os.Stat(gomodFilepath)
	if err != nil {
		return nil, fmt.Errorf("stat %s: %w", gomodFilepath, err)
	}
	gomodFileContent, err := os.ReadFile(gomodFilepath)
	if err != nil {
		return nil, fmt.Errorf("reading go.mod: %w", err)
	}
	gomod, err := modfile.Parse(gomodFilepath, gomodFileContent, nil)
	if err != nil {
		return nil, fmt.Errorf("go.mod parse: %w", err)
	}

	for modulePath, path := range modules {
		err = gomod.AddReplace(modulePath, "", path, "")
		if err != nil {
			return nil, fmt.Errorf("could not add replace statement: %w", err)
		}
	}

	data, err := gomod.Format()

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Verify req.Info.ProgramDirectory is the Go program root containing go.mod
  2. Run `go mod init` in the program directory if missing
  3. Fix path/permission problems so the file is stat-able
  4. Re-run the pulumi command after the program directory settles

Example fix

// before
cd myprogram/subdir && pulumi up
// after
cd myprogram   # directory containing go.mod
pulumi up
Defensive patterns

Strategy: validation

Validate before calling

gomod := filepath.Join(progDir, "go.mod")
if _, err := os.Stat(gomod); err != nil {
	return fmt.Errorf("program %s is not a Go module: %w", progDir, err)
}

Prevention

When it happens

Trigger: os.Stat(filepath.Join(req.Info.ProgramDirectory, "go.mod")) fails because the program directory has no go.mod or is inaccessible.

Common situations: ProgramDirectory pointing at a non-Go project or wrong path, program deleted between plugin generation steps, running the language host with a stale ProgramDirectory after a rename.

Related errors


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