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

Detect duplicate macros (#1891) #2045

Merged
merged 2 commits into from
Jan 16, 2020

Conversation

beckjake
Copy link
Contributor

Fixes #1891

Originally I wrote this as a warn_or_error, but upon reflection that made no sense, as your code will almost certainly end up doing things you don't want it to do.

I added a little helper in dbt.ui.printer that uses the stdlib textwrap and dbt's PRINTER_WIDTH to generate reasonable-seeming output.

@cla-bot cla-bot bot added the cla:yes label Jan 13, 2020
@beckjake beckjake force-pushed the feature/detect-duplicate-macros branch from ee94f4c to 706cea8 Compare January 13, 2020 19:19
@beckjake beckjake requested a review from drewbanin January 13, 2020 19:43
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

Jotted down some different copy for the error, but this otherwise looks really great.

I didn't realize textwrap was in the standard lib - really excited to leverage it more for things like this in the future! Ship this after those copy changes are addressed :)

# detect that the macro exists and emit an error
other_path = self.macros[macro.unique_id].original_file_path
# subtract 2 for the "Compilation Error" indent
msg = printer.line_wrap_message(
Copy link
Contributor

Choose a reason for hiding this comment

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

can we format this more like exceptions.raise_ambiguous_catalog_match?

dbt found two macros named "{macro.name}" in the project "{macro.package_name}".
To fix this error, rename or remove one of the following macros:
 - {macro.original_file_path}
 - {other_path}

@beckjake beckjake merged commit 1021637 into dev/barbara-gittings Jan 16, 2020
@beckjake beckjake deleted the feature/detect-duplicate-macros branch January 16, 2020 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants