pulumi/pulumi · error

could not create output directory %s: %w

Error message

could not create output directory %s: %w

What it means

When writing generated SDK files, the host creates each file's parent directory with os.MkdirAll(0o700); if that fails it returns 'could not create output directory <dir>: %w'. The message reports filepath.Dir(filename) (relative name) while the failure is on the joined path under req.Directory. Usually a permissions or existing-path-conflict problem.

Source

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

	if err != nil {
		return nil, err
	}
	rpcDiagnostics := plugin.HclDiagnosticsToRPCDiagnostics(diags)
	if diags.HasErrors() {
		return &pulumirpc.GeneratePackageResponse{
			Diagnostics: rpcDiagnostics,
		}, nil
	}
	files, err := codegen.GeneratePackage("pulumi-language-go", pkg, req.LocalDependencies)
	if err != nil {
		return nil, err
	}

	for filename, data := range files {
		outPath := filepath.Join(req.Directory, filename)
		err := os.MkdirAll(filepath.Dir(outPath), 0o700)
		if err != nil {
			return nil, fmt.Errorf("could not create output directory %s: %w", filepath.Dir(filename), err)
		}

		err = os.WriteFile(outPath, data, 0o600)
		if err != nil {
			return nil, fmt.Errorf("could not write output file %s: %w", filename, err)
		}
	}

	return &pulumirpc.GeneratePackageResponse{
		Diagnostics: rpcDiagnostics,
	}, nil
}

func (host *goLanguageHost) Pack(ctx context.Context, req *pulumirpc.PackRequest) (*pulumirpc.PackResponse, error) {
	// Go is very simple, there's nothing it can do to pack so it just copies the source to the target.

	// First read the modfile in the package directory to decide the folder name.
	data, err := os.ReadFile(filepath.Join(req.PackageDirectory, "go.mod"))

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Check permissions on the target directory (`ls -ld`, chmod/chown or pick a writable -o/--directory)
  2. Remove or rename any file occupying the conflicting path, then regenerate
  3. Verify free disk space and valid path length
  4. Run the command as a user with write access to the output location

Example fix

// before
$ pulumi package gen-sdk ... -o /usr/local/lib/sdk
error: could not create output directory sdk/go/...
// after
$ mkdir -p ~/sdks && pulumi package gen-sdk ... -o ~/sdks
Defensive patterns

Strategy: validation

Validate before calling

if err := os.MkdirAll(outDir, 0o700); err != nil {
    return fmt.Errorf("output directory %s not creatable: %w", outDir, err)
}

Try / catch

if _, err := genPackage(ctx, req); err != nil {
    if strings.Contains(err.Error(), "could not create output directory") {
        return pickWritableDirAndRegenerate()
    }
    return err
}

Prevention

When it happens

Trigger: os.MkdirAll fails while generating a package: req.Directory not writable, a file exists where a directory is needed, or the path is invalid/too long.

Common situations: Generating SDKs into a read-only checkout or root-owned directory; a stale file named like a directory (e.g. `sdk/go/...` path occupied by a file); disk full; Windows path-length limits.

Related errors


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