When catching non-jinja errors from Jinja, raise a good error message, and make a best effort at tracking down the line number and error line if possible.

This commit is contained in:
Dan 2023-02-06 12:06:37 -05:00
parent e813f3e26e
commit 7a6c63cb85
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@
import json
import os
import uuid
from sys import exc_info
from typing import Any
from typing import Dict
from typing import Optional
@ -562,6 +563,20 @@ def _render_jinja_template(unprocessed_template: str, spiff_task: SpiffTask) ->
"Jinja2 template errors can happen when trying to displaying task data"
)
raise wfe from template_error
except Exception as error:
type, value, tb = exc_info()
wfe = WorkflowTaskException(
str(error), task=spiff_task, exception=error
)
while tb:
if tb.tb_frame.f_code.co_filename == '<template>':
wfe.line_number = tb.tb_lineno
wfe.error_line = unprocessed_template.split("\n")[tb.tb_lineno - 1]
tb = tb.tb_next
wfe.add_note(
"Jinja2 template errors can happen when trying to displaying task data"
)
raise wfe from error
def _get_spiff_task_from_process_instance(