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

Fix error handling for OmegaConfigLoader #3784

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Updated CLI command `kedro catalog resolve` to read credentials properly.
* Changed the path of where pipeline tests generated with `kedro pipeline create` from `<project root>/src/tests/pipelines/<pipeline name>` to `<project root>/tests/pipelines/<pipeline name>`.
* Updated ``.gitignore`` to prevent pushing Mlflow local runs folder to a remote forge when using mlflow and git.
* Fixed error handling message for malformed yaml/json files in OmegaConfigLoader.

## Breaking changes to the API
* Methods `_is_project` and `_find_kedro_project` have been moved to `kedro.utils`. We recommend not using private methods in your code, but if you do, please update your code to use the new location.
Expand Down
2 changes: 1 addition & 1 deletion kedro/config/omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def load_and_merge_dir_config( # noqa: PLR0913
line = exc.problem_mark.line
cursor = exc.problem_mark.column
raise ParserError(
f"Invalid YAML or JSON file {Path(conf_path, config_filepath.name).as_posix()},"
f"Invalid YAML or JSON file {Path(config_filepath).as_posix()},"
f" unable to read line {line}, position {cursor}."
) from exc

Expand Down
15 changes: 9 additions & 6 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,15 @@ def test_multiple_nested_subdirs_duplicates(
assert re.search(pattern_nested_local, str(exc.value))

@use_config_dir
def test_bad_config_syntax(self, tmp_path):
conf_path = tmp_path / _BASE_ENV
conf_path.mkdir(parents=True, exist_ok=True)
(conf_path / "catalog.yml").write_text("bad:\nconfig")

pattern = f"Invalid YAML or JSON file {conf_path.as_posix()}"
@pytest.mark.parametrize("config_path", ["catalog.yml", "subfolder/catalog.yml"])
def test_bad_config_syntax(self, tmp_path: Path, config_path):
conf_env_path = tmp_path / _BASE_ENV
conf_env_path.mkdir(parents=True, exist_ok=True)
conf_path = conf_env_path / config_path
conf_path.parent.mkdir(parents=True, exist_ok=True)
(conf_env_path / config_path).write_text("bad:\nconfig")

pattern = f"Invalid YAML or JSON file {conf_env_path.as_posix()}"
with pytest.raises(ParserError, match=re.escape(pattern)):
OmegaConfigLoader(
str(tmp_path), base_env=_BASE_ENV, default_run_env=_DEFAULT_RUN_ENV
Expand Down