diff --git a/dvc/utils/serialize/_yaml.py b/dvc/utils/serialize/_yaml.py index 72d14494a..69cc4e8e1 100644 --- a/dvc/utils/serialize/_yaml.py +++ b/dvc/utils/serialize/_yaml.py @@ -23,17 +23,10 @@ def load_yaml(path, fs=None): def parse_yaml(text, path, typ="safe"): from ruamel.yaml import YAML from ruamel.yaml import YAMLError as _YAMLError - from ruamel.yaml.constructor import DuplicateKeyError yaml = YAML(typ=typ) - try: - with reraise(_YAMLError, YAMLFileCorruptedError(path)): - return yaml.load(text) or {} - except DuplicateKeyError as exc: - # NOTE: unfortunately this one doesn't inherit from YAMLError, so we - # have to catch it by-hand. See - # https://yaml.readthedocs.io/en/latest/api.html#duplicate-keys - raise YAMLError(path, exc.problem) + with reraise(_YAMLError, YAMLFileCorruptedError(path)): + return yaml.load(text) or {} def parse_yaml_for_update(text, path): diff --git a/setup.py b/setup.py index ae0c5f909..c83382837 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ install_requires = [ "grandalf==0.6", "distro>=1.3.0", "appdirs>=1.4.3", - "ruamel.yaml>=0.16.1", + "ruamel.yaml>=0.17.11", "toml>=0.10.1", "funcy>=1.14", "pathspec>=0.6.0,<0.9.0", diff --git a/tests/unit/utils/serialize/test_yaml.py b/tests/unit/utils/serialize/test_yaml.py index cca5956c9..79d23b45b 100644 --- a/tests/unit/utils/serialize/test_yaml.py +++ b/tests/unit/utils/serialize/test_yaml.py @@ -1,6 +1,11 @@ import pytest -from dvc.utils.serialize import EncodingError, YAMLError, load_yaml, parse_yaml +from dvc.utils.serialize import ( + EncodingError, + YAMLFileCorruptedError, + load_yaml, + parse_yaml, +) def test_parse_yaml_duplicate_key_error(): @@ -10,7 +15,7 @@ def test_parse_yaml_duplicate_key_error(): mykey: - bar """ - with pytest.raises(YAMLError, match='found duplicate key "mykey"'): + with pytest.raises(YAMLFileCorruptedError): parse_yaml(text, "mypath")