From 102424081ba27eef2b0078b0673d58e4449b6797 Mon Sep 17 00:00:00 2001 From: Puneet Saini <99470400+puneeter@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:29:01 +0530 Subject: [PATCH] Fix error handling for OmegaConfigLoader (#3784) * Update omegaconf_config.py Signed-off-by: Puneet Saini <99470400+puneeter@users.noreply.github.com> * Update RELEASE.md Signed-off-by: Puneet Saini <99470400+puneeter@users.noreply.github.com> * add a more complicated test case Signed-off-by: Nok --------- Signed-off-by: Puneet Saini <99470400+puneeter@users.noreply.github.com> Signed-off-by: Nok Co-authored-by: Nok Signed-off-by: Ahdra Merali --- RELEASE.md | 1 + kedro/config/omegaconf_config.py | 2 +- tests/config/test_omegaconf_config.py | 15 +++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 535b6e7d9e..6655c14a9e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -18,6 +18,7 @@ * Updated CLI command `kedro catalog resolve` to read credentials properly. * Changed the path of where pipeline tests generated with `kedro pipeline create` from `/src/tests/pipelines/` to `/tests/pipelines/`. * 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. diff --git a/kedro/config/omegaconf_config.py b/kedro/config/omegaconf_config.py index 6b67e047b7..2145ad3331 100644 --- a/kedro/config/omegaconf_config.py +++ b/kedro/config/omegaconf_config.py @@ -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 diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index 3ec2b39074..676963ee18 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -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