diff --git a/core/dbt/cli/option_types.py b/core/dbt/cli/option_types.py index ef04e348260..544b09bee2a 100644 --- a/core/dbt/cli/option_types.py +++ b/core/dbt/cli/option_types.py @@ -51,8 +51,12 @@ class WarnErrorOptionsType(YAML): def convert(self, value, param, ctx): # this function is being used by param in click include_exclude = super().convert(value, param, ctx) - exclusive_primary_alt_value_setting(include_exclude, "include", "error") - exclusive_primary_alt_value_setting(include_exclude, "exclude", "warn") + exclusive_primary_alt_value_setting( + include_exclude, "include", "error", "warn_error_options" + ) + exclusive_primary_alt_value_setting( + include_exclude, "exclude", "warn", "warn_error_options" + ) return WarnErrorOptions( include=include_exclude.get("include", []), diff --git a/core/dbt/config/project.py b/core/dbt/config/project.py index 7309df3cbd6..52b20e5179d 100644 --- a/core/dbt/config/project.py +++ b/core/dbt/config/project.py @@ -27,7 +27,7 @@ from dbt.adapters.contracts.connection import QueryComment from dbt.exceptions import ( DbtProjectError, - DbtWarnErrorOptionsError, + DbtExclusivePropertyUseError, ProjectContractBrokenError, ProjectContractError, DbtRuntimeError, @@ -840,12 +840,16 @@ def read_project_flags(project_dir: str, profiles_dir: str) -> ProjectFlags: # handle collapsing `include` and `error` as well as collapsing `exclude` and `warn` # for warn_error_options warn_error_options = project_flags.get("warn_error_options") - exclusive_primary_alt_value_setting(warn_error_options, "include", "error") - exclusive_primary_alt_value_setting(warn_error_options, "exclude", "warn") + exclusive_primary_alt_value_setting( + warn_error_options, "include", "error", "warn_error_options" + ) + exclusive_primary_alt_value_setting( + warn_error_options, "exclude", "warn", "warn_error_options" + ) ProjectFlags.validate(project_flags) return ProjectFlags.from_dict(project_flags) - except (DbtProjectError, DbtWarnErrorOptionsError) as exc: + except (DbtProjectError, DbtExclusivePropertyUseError) as exc: # We don't want to eat the DbtProjectError for UserConfig to ProjectFlags or # DbtConfigError for warn_error_options munging raise exc diff --git a/core/dbt/config/utils.py b/core/dbt/config/utils.py index b3a40af884a..f94e5dce0ad 100644 --- a/core/dbt/config/utils.py +++ b/core/dbt/config/utils.py @@ -4,7 +4,7 @@ from dbt.clients import yaml_helper from dbt_common.events.functions import fire_event from dbt.events.types import InvalidOptionYAML -from dbt.exceptions import DbtWarnErrorOptionsError, OptionNotYamlDictError +from dbt.exceptions import DbtExclusivePropertyUseError, OptionNotYamlDictError from dbt_common.exceptions import DbtValidationError @@ -26,7 +26,10 @@ def parse_cli_yaml_string(var_string: str, cli_option_name: str) -> Dict[str, An def exclusive_primary_alt_value_setting( - dictionary: Optional[Dict[str, Any]], primary: str, alt: str + dictionary: Optional[Dict[str, Any]], + primary: str, + alt: str, + parent_config: Optional[str] = None, ) -> None: """Munges in place under the primary the options for the primary and alt values @@ -42,8 +45,9 @@ def exclusive_primary_alt_value_setting( alt_options = dictionary.get(alt) if primary_options and alt_options: - raise DbtWarnErrorOptionsError( - f"Only `{alt}` or `{primary}` can be specified in `warn_error_options`, not both" + where = f" in `{parent_config}`" if parent_config is not None else "" + raise DbtExclusivePropertyUseError( + f"Only `{alt}` or `{primary}` can be specified{where}, not both" ) if alt_options: diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index a692fad5389..ea44f0c055c 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -113,7 +113,7 @@ class DbtProfileError(DbtConfigError): pass -class DbtWarnErrorOptionsError(DbtConfigError): +class DbtExclusivePropertyUseError(DbtConfigError): pass diff --git a/tests/unit/config/test_utils.py b/tests/unit/config/test_utils.py index 57ede0dfb00..d2d7f99499d 100644 --- a/tests/unit/config/test_utils.py +++ b/tests/unit/config/test_utils.py @@ -1,7 +1,7 @@ import pytest from dbt.config.utils import exclusive_primary_alt_value_setting -from dbt.exceptions import DbtWarnErrorOptionsError +from dbt.exceptions import DbtExclusivePropertyUseError class TestExclusivePrimaryAltValueSetting: @@ -31,7 +31,7 @@ def test_alt_set(self, primary_key: str, alt_key: str, value: str): def test_primary_and_alt_set(self, primary_key: str, alt_key: str, value: str): test_dict = {primary_key: value, alt_key: value} - with pytest.raises(DbtWarnErrorOptionsError): + with pytest.raises(DbtExclusivePropertyUseError): exclusive_primary_alt_value_setting(test_dict, primary_key, alt_key) def test_neither_primary_nor_alt_set(self, primary_key: str, alt_key: str):