-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improve CompilationException messaging for generic test Jinja rendering #5393
Conversation
The error message rendered from the `UndefinedMacroException` when raised by a TestBuilder is very vague as to where the problem is and how to resolve it. This commit adds a basic amount of information about the specific model and column that is referencing an undefined macro. Note: All custom macros referenced in a generic test config will raise an UndefinedMacroException as of v0.20.0.
I realized that this exception information would be better if CompilationExceptions inclulded the file that raised the exception. To that end, I created a new exception handler in `_parse_generic_test` to report on CompilationExceptions raised during the parsing of generic tests. Along the way I reformatted the message returned from TestBuilder to play nicely with the the existing formatting of `_parse_generic_test`'s exception handling code.
I've added a basic test to confirm that the approriate CompilationException when a custom macro is referenced in a generic test config.
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The messages need a bit more work but this is on the right track!
Thanks to @emmyoop for the recommendation that this be listed as a Fix change instead of an "Under the Hood" change! Co-authored-by: Emily Rockman <[email protected]>
I've simplified the error message raised during a Compilation Error sourced from a test config. Mainly by way of removing tabs and newlines where not required.
This commit moves a format call to a multiline fstring in the schemas.py file for CompilationExceptions.
Thank you for the thoughtful feedback @emmyoop! I believe I've made all of the requested changes. Please let me know if I'm missing anything! 😁 |
raise_compiler_error( | ||
f"The {self.target.name}.{column_name} column's " | ||
f'"{self.name}" test references an undefined ' | ||
f"macro in its {key} configuration argument. " | ||
f"The macro {e.msg}.\n" | ||
"Please note that the generic test configuration parser " | ||
"currently does not support using custom macros to " | ||
"populate configuration values" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtcohen6 Do you have any thoughts in the wording of this exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new error message format looks great to me 👍
The thing that will be super helpful is having all the additional context to help troubleshoot 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! This is a nice improvement to messaging @nicholasyager!
…ng (dbt-labs#5393) * feat: Improve generic test UndefinedMacroException message The error message rendered from the `UndefinedMacroException` when raised by a TestBuilder is very vague as to where the problem is and how to resolve it. This commit adds a basic amount of information about the specific model and column that is referencing an undefined macro. Note: All custom macros referenced in a generic test config will raise an UndefinedMacroException as of v0.20.0. * feat: Bubble CompilationException into schemas.py I realized that this exception information would be better if CompilationExceptions inclulded the file that raised the exception. To that end, I created a new exception handler in `_parse_generic_test` to report on CompilationExceptions raised during the parsing of generic tests. Along the way I reformatted the message returned from TestBuilder to play nicely with the the existing formatting of `_parse_generic_test`'s exception handling code. * feat: Add tests to confirm CompileException I've added a basic test to confirm that the approriate CompilationException when a custom macro is referenced in a generic test config. * feat: Add changie entry and tweak error msg * Update .changes/unreleased/Under the Hood-20220617-150744.yaml Thanks to @emmyoop for the recommendation that this be listed as a Fix change instead of an "Under the Hood" change! Co-authored-by: Emily Rockman <[email protected]> * fix: Simplified Compliation Error message I've simplified the error message raised during a Compilation Error sourced from a test config. Mainly by way of removing tabs and newlines where not required. * fix: Convert format to fstring in schemas This commit moves a format call to a multiline fstring in the schemas.py file for CompilationExceptions. Co-authored-by: Emily Rockman <[email protected]>
Resolves #5294
Description
In issue #5294, the reporter was having difficulties identifying the source of a
CompliationException
during a migration from 0.19.1 to 1.0.1. The original error message is as follows:The message above does not provide any context as to where the issue was originating from.
This PR adds an exception handler for
UndefinedMacroException
s to theTestBuilder
class so that additional context can be added to the exception raised in the event that a custom macro (or otherwise undefined macro) is reference in a generic test's configuration values. Additionally, aCompilationException
exception handler was added to the_parse_generic_test
method ofSchemaParser
so that the schema file that raised theCompilationException
is also reported.The new exception message is as follows:
A test has been added to confirm that a
CompilationException
is raised as expected when a custom macro is referenced in a generic test's config values, and to confirm that the appropriate exception message is returned.Checklist
changie new
to create a changelog entry