diff --git a/RELEASE.md b/RELEASE.md index 366ab3a5fd..be53347946 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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 `/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