Skip to content

Commit 82049d8

Browse files
committed
task: log invalid rendered manifest in Task.render_file()
After rendering the manifest file, we want to parse and print it in debug logging. That is very useful to see what we did. Jinja2 is plain text replacement and unaware that the template is supposed to end up as valid YAML. Catch errors while re-parsing the rendered file as YAML and log an error message with the full content before failing. Signed-off-by: Thomas Haller <[email protected]>
1 parent c56ce6d commit 82049d8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

task.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,14 @@ def render_file(
382382
out_file=out_file_yaml,
383383
)
384384

385-
rendered_dict = yaml.safe_load(rendered)
385+
try:
386+
rendered_dict = yaml.safe_load(rendered)
387+
except Exception as e:
388+
logger.error(
389+
f'"{in_file_template}" rendered as {repr(rendered)} is not valid YAML: {e}'
390+
)
391+
raise
392+
386393
logger.debug(f'"{in_file_template}" contains: {json.dumps(rendered_dict)}')
387394

388395
def initialize(self) -> None:

0 commit comments

Comments
 (0)