Support error raising on missing variables and partials#109
Open
tzoiker wants to merge 1 commit intonoahmorrison:mainfrom
Open
Support error raising on missing variables and partials#109tzoiker wants to merge 1 commit intonoahmorrison:mainfrom
tzoiker wants to merge 1 commit intonoahmorrison:mainfrom
Conversation
|
When will this get merged? |
|
I'm using the following logic to validate if there are missing variables: rendered_content = chevron.render(template, context)
# Find all variables in the template
variables = re.findall(r'{{\s*([\w.]+)\s*}}', template)
# Check if any variable resulted in an empty string
for var in variables:
var_rendered = chevron.render("{{" + var + "}}", context)
if var_rendered == "":
raise Exception(f"Variable '{var}' is missing from context or resulted in an empty string.") |
|
@noahmorrison Any indication if this can/will get merged? We are in need of this behavior as well to be able to catch an exception when a there is a missing variables as that indicates there's a bug and we do not want to silently continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Due to security issues we decided to migrate from jinja to mustache. Jinja supports error raising for missing variables, which is good for data validation purposes. Proposition:
errorflag to render (incompatible withkeep,warn);UndefinedErroronly forvariable,no escape,partial.