pulumi/pulumi · error

generation failed: %w

Error message

generation failed: %w

What it means

Wraps the diagnostic set returned by the language host's GeneratePackage call when code generation reports errors (diags.HasErrors()). The schema was received and a temp dir created, but the per-language SDK generator produced fatal diagnostics. The message joins the diagnostics with cleanup errors (closing the plugin and removing the temp dir).

Source

Thrown at pkg/cmd/pulumi/packageworkspace/packageworkspace.go:440

	if err != nil {
		return "", err
	}
	tmpDir, err := os.MkdirTemp("", "pulumi-package-")
	if err != nil {
		return "", fmt.Errorf("unable to make temp dir: %w", err)
	}
	s, err := w.servers(ctx, language, tmpDir, pkg.Reference())
	if err != nil {
		return "", errors.Join(err, os.RemoveAll(tmpDir))
	}

	diags, err := s.lang.GeneratePackage(ctx, tmpDir, string(jsonBytes), nil, s.pctx.LoaderAddr(), nil, true /* local */)
	if err != nil {
		return "", errors.Join(err, s.Close(), os.RemoveAll(tmpDir))
	}

	if diags.HasErrors() {
		return "", errors.Join(fmt.Errorf("generation failed: %w", diags),
			s.Close(), os.RemoveAll(tmpDir))
	}

	return tmpDir, s.Close()
}

// Run a package from a directory, parameterized by params.
func (w Workspace) RunPackage(
	ctx context.Context, rootDir, pluginPath string, params plugin.ParameterizeParameters,
	originalSpec workspace.PackageSpec,
) (plugin.Provider, error) {
	tracer := otel.Tracer("pulumi-cli")
	ctx, span := diagutils.StartSpan(ctx, tracer, "run-plugin",
		trace.WithAttributes(
			attribute.String("path", pluginPath),
		))
	defer span.End()

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Read the joined diagnostics in the error for the specific codegen failures
  2. Update the provider plugin and Pulumi CLI to latest versions
  3. Regenerate with a different language target to isolate whether the schema or the language generator is at fault
  4. Fix or work around the offending schema types in the provider
  5. Report an issue if valid schema triggers codegen errors
Defensive patterns

Strategy: try-catch

Try / catch

tmpDir, err := generatePackage(...)
if err != nil {
    var dgerr interface{ HasErrors() bool }
    if errors.As(err, &dgerr) && dgerr.HasErrors() {
        log.Printf("codegen diagnostics: %v", err) // inspect joined diags
    }
    return err
}

Prevention

When it happens

Trigger: A plugin/SDK generation run where s.lang.GeneratePackage returns diagnostics containing errors — e.g. invalid or unsupported schema constructs, unsupported types, codegen bugs for the target language.

Common situations: Generating SDKs for providers with exotic or invalid schemas, newer schema features unsupported by the installed language codegen, mismatched provider/plugin versions, or custom parameterized packages with unusual types.

Related errors


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