pulumi/pulumi · error

error parsing pcl: %w

Error message

error parsing pcl: %w

What it means

This error wraps a failure from `getPackagesToGenerateSdks(sourceDirectory)` during `pulumi convert`'s PCL-to-language path. That helper parses the source directory's PCL files with the pcl binder to find `package` blocks so SDKs can be generated for them. If the PCL source does not parse (syntax errors or binder diagnostics escalated to an error), the conversion aborts with "error parsing pcl".

Source

Thrown at pkg/cmd/pulumi/convert/convert.go:326

						if err != nil {
							return false
						}
						// if the target directory is a subdirectory of the source directory,
						// skip copying it over
						return sourceAbsPath != targetAbsPath
					}

					return file.Name() != "Pulumi.yaml" &&
						path.Ext(file.Name()) != ".pp"
				})
			if err != nil {
				return nil, fmt.Errorf("copying files from source directory: %w", err)
			}

			packageBlockDescriptors, ds, err := getPackagesToGenerateSdks(sourceDirectory)
			diags = append(diags, ds...)
			if err != nil {
				return diags, fmt.Errorf("error parsing pcl: %w", err)
			}

			err = generateAndLinkSdksForPackages(
				pCtx,
				stdout,
				language,
				targetDirectory,
				packageBlockDescriptors,
				generateOnly,
				cmdCmd.NewDefaultRegistry(ctx, lm, ws, proj, cmdutil.Diag(), e),
			)
			if err != nil {
				return diags, fmt.Errorf("error generating packages: %w", err)
			}

			return diags, nil
		}
	}

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Run `pulumi convert --language pcl` first and inspect the returned hcl.Diagnostics for the exact file/line of the parse failure
  2. Fix the reported PCL syntax/type errors in the .pp files in the source directory
  3. Upgrade the Pulumi CLI to the latest version in case the source was generated by a newer converter
  4. Reduce the program to a minimal .pp file and re-add declarations until the offending construct is found

Example fix

// before (invalid PCL)
resource bucket "aws:s3:Bucket" {
    acl = true
}
// after
resource bucket "aws:s3:Bucket" {
    acl = "private"
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate PCL before converting
out, err := exec.Command("pulumi", "convert", "--from", "pcl", "--language", "pcl", "--out", tmpDir).CombinedOutput()
if err != nil {
    return fmt.Errorf("PCL failed to parse, fix these diagnostics first:\n%s", out)
}

Try / catch

if err != nil {
    var diags hcl.Diagnostics
    if errors.As(err, &diags) {
        for _, d := range diags {
            fmt.Printf("%s:%d: %s\n", d.Subject.Filename, d.Subject.Start.Line, d.Summary)
        }
    }
}

Prevention

When it happens

Trigger: Running `pulumi convert --from pcl --language <lang>` where the source directory contains .pp files with PCL syntax errors, unrecognized constructs, or a binder failure inside getPackagesToGenerateSdks.

Common situations: Hand-written or hand-edited PCL programs; PCL produced by an older/newer converter that emits constructs the current binder cannot parse; typos in resource declarations or invalid config types in .pp files.

Related errors


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