-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[CT-73] [Feature] Better error messages: include line number and location for Compilation Error #4596
Comments
Thanks for the feature request @tekumara! I think the addition of line numbers would be a big help debugging dbt projects, and I couldn't find any previous feature requests for this. I do want to point out that the particular error you're running into is an internal Python error that should never be raised to users. If you have a clear minimal reproduction case for that, it would be very helpful if you could log a bug ticket for what causes However, with other compilation errors such as models depending on models that do not exist (typo in model name) or calling an undefined macro (typo in macro name), line numbers are still not included today. I see that you're interested in contributing to this feature, which we greatly appreciate. To implement this I believe we would have to preserve line numbers when we read files, and check them on every exception that we raise. This isn't exactly a small lift, and we have tentative plans to centralize exceptions to the event module which may help prepare for this kind of effort. |
Talking to the team, this might be a bit more complicated to get line numbers because a lot of this work is done in batches by jinja where we won't be able to preserve line-level granularity. However, we might be able to point out the location of the jinja blocks that contain errors when jinja raises them. If you decide to open up a PR please feel free to tag me as a reviewer. |
To provide a concrete/motivating example, if you include the following code in a model: -- models/my_model.sql
{% set mylist = None %}
{% for item in mylist %}
select '{{ item }}' as my_item
{{ 'union all' if not loop.last }}
{% endfor %}
You'll see the reported error:
In this case, it's with even fewer helpful pointers — not even a mention that the error was encountered while parsing |
I just spoke with @jtcohen6 about this, and for anyone who wants to try and get this working in a PR, this is where many of the jinja blocks end up being rendered, and there's an existing context manager that catches jinja rendering exceptions to raise better dbt exceptions. Additionally, instead of threading line numbers through, we could just return the text of the offending jinja block which might be an easier lift. |
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days. |
This is on my list of things to get to (cc @ehmartens) so let's leave it open! |
I also spent a few hours tracking down the source of a The dbt exceptions.raise_compiler_error method was very useful for debugging (and useful to leave in as a precondition check), since jinja doesn't have standard Python exception/assert mechanisms. Here's a basic example in case others find it a useful workaround: {% if my_list == None %}
{{ exceptions.raise_compiler_error("Invalid `my_list`. Got: " ~ my_list) }}
{% endif %} |
I'm getting
Its very difficult which macro is breaking at what point |
Is there an existing feature request for this?
Describe the Feature
When encountering a Compilation error it's not clear which line the error is on, eg:
Describe alternatives you've considered
No response
Who will this benefit?
Anyone trying to debug compilation errors
Are you interested in contributing this feature?
Yes
Anything else?
dbt 1.0.1
The text was updated successfully, but these errors were encountered: