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

No error messages when accessing undefined variables in config templating #70

Open
mikn opened this issue Dec 21, 2024 · 2 comments
Open

Comments

@mikn
Copy link

mikn commented Dec 21, 2024

So, poking around in your settings system I noticed that the templates, both on the input from the user-data.toml and to the output in the templates, you use kebab-case, but in rust you use snake_case (few programming languages allow you to use kebab-case, I guess).

This took me an embarrassingly long time to figure out (I just assumed that since it was decoded into rust structs with snake_case, that the templating would use snake_case also).

Ultimately, what was not ergonomic in this was that I got no real error when trying to access template variables that does not exist and is not set. You do take great care to validate it in Rust, etc - perhaps there is a way to make sure that when accessing variables in the templating stage, that you check that the variable exists? Would have saved me a lot of time!

@mikn mikn changed the title Usage of both kebab-case and snake_case i n templating is very confusing Usage of both kebab-case and snake_case in templating is confusing Dec 21, 2024
@mikn mikn changed the title Usage of both kebab-case and snake_case in templating is confusing No error messages when accessing undefined variables in config templating Dec 21, 2024
@cbgbt
Copy link
Contributor

cbgbt commented Dec 24, 2024

Hey @mikn, thanks for the report.

The template renderer is supposed to throw an error if we attempt to use a variable which isn't defined. We enable strict mode when constructing the template registry (relevant docs).

I wonder if we are rendering templates via a codepath that doesn't use these registry settings, or if these errors are not surfaced in a way that makes problems clear.

@cbgbt
Copy link
Contributor

cbgbt commented Dec 24, 2024

Yep, we don't use that codepath when we render template files in Bottlerocket.

Here's where we render templates, and that calls this function which does not use the registry code I linked above.

Phooey, I almost certainly introduced this regression when I last worked on schnauzer.

We can re-enable strict mode for these renderings, but we'll need to be very cautious in doing so -- it's a backwards incompatible change for core-kit. Existing templates which successfully render today could very well stop.

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

No branches or pull requests

2 participants