Skip to content

Commit

Permalink
include name from original project if the compiler doesn't return it
Browse files Browse the repository at this point in the history
The pulumi-yaml runtime expects the compiler to return a complete yaml
project, including the `name` attribute. The compiler might not return
this however, even when it returns a valid yaml program otherwise.

This leads to issues down the line, as the rest of the runtime expects
the name to be set in the template, and might panic if it isn't.  We
do however have the name from the original Pulumi.yaml, so we can fill
that in for the user, even if the compiler doesn't return it in the
template.
  • Loading branch information
tgummerer committed Aug 9, 2024
1 parent 1332be6 commit c921f64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Improvements

### Bug Fixes

- Fix a panic when the compiler doesn't include the name attribute from the Pulumi.yaml.
9 changes: 9 additions & 0 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,19 @@ func LoadFromCompiler(compiler string, workingDirectory string, env []string) (*
if stdout.Len() != 0 {
diags = append(diags, syntax.Warning(nil, fmt.Sprintf("compiler %v warnings: %v", name, stdout.String()), ""))
}

templateStr := stdout.String()
template, tdiags, err := LoadYAMLBytes(fmt.Sprintf("<stdout from compiler %v>", name), []byte(templateStr))
diags.Extend(tdiags...)

if template.Name == nil {
uncompiledTemplate, _, err := LoadDir(workingDirectory)
if err != nil || uncompiledTemplate.Name == nil {
return nil, diags, errors.New("compiler did not produce a valid template")
}
template.Name = uncompiledTemplate.Name
}

return template, tdiags, err
}

Expand Down

0 comments on commit c921f64

Please sign in to comment.