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

packer validate . outputs same error message multiple times for unsupported block types #13241

Open
gstvcruz opened this issue Dec 20, 2024 · 4 comments · May be fixed by #13245
Open

packer validate . outputs same error message multiple times for unsupported block types #13241

gstvcruz opened this issue Dec 20, 2024 · 4 comments · May be fixed by #13245
Labels

Comments

@gstvcruz
Copy link

gstvcruz commented Dec 20, 2024

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Overview of the Issue

packer validate . outputs the same error message exactly four times for each unsupported root block type found per packer template.

Reproduction Steps

Introduce any amount of unsupported root block types in any packer template. Nested blocks aren't affected.

Packer version

v1.11.2

Simplified Packer Template

e.g., src instead of source, but it happens for any unsupported block type.

packer {
...
}

src "docker" "ubuntu" {
...
}

build {
...
}

Operating system and Environment details

Ubuntu 24.04 x86_64

@gstvcruz gstvcruz added the bug label Dec 20, 2024
@gstvcruz
Copy link
Author

I would like to deal with this issue if it is in fact a bug.

@mogrogan
Copy link
Contributor

Thanks @gstvcruz for the report

I just tried on my local machine seems like you're right. it does look like a bug. If you want to take a bite at it, be my guest! We warmly welcome contribution :)

@gstvcruz
Copy link
Author

gstvcruz commented Dec 20, 2024

When parsing a packer template, there are four stages: decoding the required plugins block, decoding input variables, decoding data sources, and parsing local variable blocks.

Each stage processes the file's body content to validate the arguments and block types for every block in the file. As a result, the same error message may be appended to the output at each stage for unsupported block types.

I'm new to Go and have never contributed to an open-source project before, especially one of this size. However, I think I'm onto something. I suppose it’s just a matter of avoiding unnecessary appendages—perhaps by checking the already appended message summary against the summary of the message to be appended? Another simpler approach would be to just remove duplicates from the output, which comes from a slice of error messages.

@gstvcruz
Copy link
Author

It seems I've fixed it! Every stage was checking for invalid arguments or unsupported block types using the same function, so I refactored it into a for loop to check every file instead. All tests have passed. I'll review the CONTRIBUTING.md file to figure out the next steps for integrating these changes.

@gstvcruz gstvcruz linked a pull request Dec 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants