Skip to content

Commit

Permalink
Fix error handling for OmegaConfigLoader (#3784)
Browse files Browse the repository at this point in the history
* 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 <nok.lam.chan@quantumblack.com>

---------

Signed-off-by: Puneet Saini <99470400+puneeter@users.noreply.github.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Co-authored-by: Nok <nok.lam.chan@quantumblack.com>
  • Loading branch information
puneeter and noklam authored Apr 5, 2024
1 parent ff2baad commit f58740d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
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

0 comments on commit f58740d

Please sign in to comment.