Skip to content

Commit

Permalink
Use DbtWarnErrorOptionsError in `exclusive_primary_alt_value_settin…
Browse files Browse the repository at this point in the history
…g` instead of `DbtConfigError`

Using `DbtConfigError` seemed reasonable. However in order to make sure the error
got raised in `read_project_flags` we had to mark it to be `DbtConfigError`s to be
re-raised. This had the uninteded consequence of reraising a smattering of errors
which were previously being swallowed. I'd argue that if those are errors we're
swallowing, the functions that raise those errors should be modified perhaps to
conditionally not raise them, but that's not the world we live in and is out of
scope for this branch of work. Thus instead we've created a error specific to
`WarnErrorOptions` issues, and now use, and catch for re-raising.
  • Loading branch information
QMalcolm committed Apr 26, 2024
1 parent 3eb4e0c commit 53d61f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from dbt.clients.yaml_helper import load_yaml_text
from dbt.adapters.contracts.connection import QueryComment
from dbt.exceptions import (
DbtConfigError,
DbtProjectError,
DbtWarnErrorOptionsError,
ProjectContractBrokenError,
ProjectContractError,
DbtRuntimeError,
Expand Down Expand Up @@ -846,7 +846,7 @@ def read_project_flags(project_dir: str, profiles_dir: str) -> ProjectFlags:

ProjectFlags.validate(project_flags)
return ProjectFlags.from_dict(project_flags)
except (DbtProjectError, DbtConfigError) as exc:
except (DbtProjectError, DbtWarnErrorOptionsError) as exc:
# We don't want to eat the DbtProjectError for UserConfig to ProjectFlags or
# DbtConfigError for warn_error_options munging
raise exc
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from dbt.clients import yaml_helper
from dbt_common.events.functions import fire_event
from dbt.events.types import InvalidOptionYAML
from dbt.exceptions import OptionNotYamlDictError
from dbt_common.exceptions import DbtConfigError, DbtValidationError
from dbt.exceptions import DbtWarnErrorOptionsError, OptionNotYamlDictError
from dbt_common.exceptions import DbtValidationError


def parse_cli_vars(var_string: str) -> Dict[str, Any]:
Expand Down Expand Up @@ -39,7 +39,7 @@ def exclusive_primary_alt_value_setting(
alt_options = dictionary.get(alt)

if primary_options and alt_options:
raise DbtConfigError(
raise DbtWarnErrorOptionsError(

Check warning on line 42 in core/dbt/config/utils.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/config/utils.py#L42

Added line #L42 was not covered by tests
f"Only `{alt}` or `{primary}` can be specified in `warn_error_options`, not both"
)

Expand Down
4 changes: 4 additions & 0 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class DbtProfileError(DbtConfigError):
pass


class DbtWarnErrorOptionsError(DbtConfigError):
pass


class InvalidSelectorError(DbtRuntimeError):
def __init__(self, name: str) -> None:
self.name = name
Expand Down

0 comments on commit 53d61f9

Please sign in to comment.