Chore: Provide additional info in jinja rendering errors#5318
Chore: Provide additional info in jinja rendering errors#5318themisvaltinos merged 5 commits intomainfrom
Conversation
sqlmesh/core/renderer.py
Outdated
| if isinstance(ex, UndefinedError): | ||
| try: | ||
| _, _, exc_traceback = exc_info() | ||
| for frame, _ in walk_tb(exc_traceback): |
There was a problem hiding this comment.
I guess this is necessary because Jinja gets turned into a Python script and run.
Are you able to add a test that exercises this codepath and shows the expected results?
There was a problem hiding this comment.
yes added tests for native and dbt project for this
78061a7 to
57e3fe8
Compare
|
thanks for the review @erindru and for the offline feedback @georgesittas and @crericha! addressed comments as discussed:
|
|
Quick heads up about https://github.com/TobikoData/sqlmesh/pull/5330– it'll cause conflicts with this one. |
sqlmesh/core/renderer.py
Outdated
| error_msg = f"Could not render or parse jinja for '{self._path}'.\n" + ( | ||
| extract_error_details(ex) or f"{ex}" | ||
| ) |
There was a problem hiding this comment.
Nit: can we just fallback to str(ex) within extract_error_details instead of needing an or here?
There was a problem hiding this comment.
sure good point, added the fallback within the method
7891e26 to
2a18eb4
Compare
This PR adds a best effort frame analysis to identify the specific macro invocation that triggered the jinja error.
Currently, when the macro rendering fails, the error message only references the model containing the macro, but not which macro led to this error:

With this change the error message is augmented with the originating macro to improve debugging:
