Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when resource shape is invalid #677

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

Zaid-Ajaj
Copy link
Contributor

Fixes #668

I believe the issue is that we assign packages to the parsed template without checking diagnostics:

packages, err := packages.SearchPackageDecls(directory)
template.Packages = packages

@Zaid-Ajaj Zaid-Ajaj marked this pull request as ready for review November 15, 2024 00:03
@Zaid-Ajaj Zaid-Ajaj requested a review from a team as a code owner November 15, 2024 00:03
@@ -133,6 +133,10 @@ func LoadDir(directory string) (*ast.TemplateDecl, syntax.Diagnostics, error) {
return nil, diags, err
}

if diags.HasErrors() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we still do SeachPackageDecls so we can add that to the diagnostics as well if it errors but then check if template is nil just before assigning Packages to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean if the template has errors while parsing, we would early exit like most Go functions, unless it is a pattern to combine errors from functions downstream. I don't have a strong opinion about this, could fix it either way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh fine, easy to change if a compelling reason comes up later

@Zaid-Ajaj Zaid-Ajaj merged commit 3c4dea6 into main Nov 16, 2024
6 checks passed
@Zaid-Ajaj Zaid-Ajaj deleted the zaid/invalid-resource-shape-should-not-panic branch November 16, 2024 02:00
@pulumi-bot
Copy link

This PR has been shipped in release v1.12.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on invalid resource when valid error is expected
3 participants