Skip to content

Commit

Permalink
Update error message when catalog entry is invalid (#3944)
Browse files Browse the repository at this point in the history
* Update error message when catalog entry is invalid

Signed-off-by: Ankita Katiyar <[email protected]>

* Update error message for dict type as well

Signed-off-by: Ankita Katiyar <[email protected]>

* Move error message

Signed-off-by: Ankita Katiyar <[email protected]>

---------

Signed-off-by: Ankita Katiyar <[email protected]>
  • Loading branch information
ankatiyar authored Jun 13, 2024
1 parent 3c46b41 commit b6e585f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Major features and improvements

## Bug fixes and other changes
* Updated error message for invalid catalog entries.

## Breaking changes to the API

Expand Down
8 changes: 6 additions & 2 deletions kedro/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def from_config(
except Exception as exc:
raise DatasetError(
f"An exception occurred when parsing config "
f"for dataset '{name}':\n{str(exc)}"
f"for dataset '{name}':\n{str(exc)}."
) from exc

try:
Expand Down Expand Up @@ -384,7 +384,11 @@ def parse_dataset_definition(
config = copy.deepcopy(config)

if "type" not in config:
raise DatasetError("'type' is missing from dataset catalog configuration")
raise DatasetError(
"'type' is missing from dataset catalog configuration."
"\nHint: If this catalog entry is intended for variable interpolation, "
"make sure that the top level key is preceded by an underscore."
)

dataset_type = config.pop("type")
class_obj = None
Expand Down
7 changes: 7 additions & 0 deletions kedro/io/data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ class to be loaded is specified with the key ``type`` and their
user_default = {}

for ds_name, ds_config in catalog.items():
if not isinstance(ds_config, dict):
raise DatasetError(
f"Catalog entry '{ds_name}' is not a valid dataset configuration. "
"\nHint: If this catalog entry is intended for variable interpolation, "
"make sure that the key is preceded by an underscore."
)

ds_config = _resolve_credentials( # noqa: PLW2901
ds_config, credentials
)
Expand Down
10 changes: 10 additions & 0 deletions tests/io/test_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ def test_config_invalid_arguments(self, sane_config):
with pytest.raises(DatasetError, match=pattern):
DataCatalog.from_config(**sane_config)

def test_config_invalid_dataset_config(self, sane_config):
sane_config["catalog"]["invalid_entry"] = "some string"
pattern = (
"Catalog entry 'invalid_entry' is not a valid dataset configuration. "
"\nHint: If this catalog entry is intended for variable interpolation, "
"make sure that the key is preceded by an underscore."
)
with pytest.raises(DatasetError, match=pattern):
DataCatalog.from_config(**sane_config)

def test_empty_config(self):
"""Test empty config"""
assert DataCatalog.from_config(None)
Expand Down

0 comments on commit b6e585f

Please sign in to comment.