Skip to content
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

Add a skip and better logging for fatal dbt issues #3603

Merged
merged 4 commits into from Jul 13, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions plugins/sqlfluff-templater-dbt/sqlfluff_templater_dbt/templater.py
Expand Up @@ -464,6 +464,20 @@ def make_template(in_str):
node=node,
manifest=self.dbt_manifest,
)
except Exception as err:
templater_logger.exception(
"Fatal dbt compilation error on %s. This occurs most often "
"during incorrect sorting of ephemeral models before linting. "
"Please report this error on github at "
"https://github.com/sqlfluff/sqlfluff/issues, including "
"both the raw and compiled sql for the model affected.",
fname,
)
# Additional error logging in case we get a fatal dbt error.
raise SQLTemplaterSkipFile( # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the logging look like from this? Curious if we should do one or both of:

Logging where the exception was raised from:

logger.exception("<<MESSAGE>>")

Exception chaining:

raise SQLTemplaterSkipFile(...) from err

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are things I've never used before 🤔 .

On reading - I think we should definitely do the latter. I think it will still result in a skipped file. Doing the former seems like a good idea too. Perhaps with some more information attached.

Great ideas!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit of a Python 🤓, I suppose. 😝

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at what I've done now. Used both 🤓

f"Skipped file {fname} because dbt raised a fatal "
f"exception during compilation: {err!s}"
) from err
finally:
# Undo the monkeypatch.
Environment.from_string = old_from_string
Expand Down