diff --git a/dvc/exceptions.py b/dvc/exceptions.py index e4d91dcee2..8192365d93 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -17,6 +17,10 @@ def __init__(self, msg, *args): class InvalidArgumentError(ValueError, DvcException): """Thrown if arguments are invalid.""" + def __init__(self, msg, *args): + self.msg = msg + super().__init__(msg, *args) + class OutputDuplicationError(DvcException): """Thrown if a file/directory is specified as an output in more than one diff --git a/tests/func/artifacts/test_artifacts.py b/tests/func/artifacts/test_artifacts.py index 424d7f047f..cf6c422036 100644 --- a/tests/func/artifacts/test_artifacts.py +++ b/tests/func/artifacts/test_artifacts.py @@ -1,4 +1,6 @@ +import logging import os +from copy import deepcopy import pytest @@ -39,6 +41,22 @@ def test_artifacts_read_subdir(tmp_dir, dvc): } +def test_artifacts_read_bad_name(tmp_dir, dvc, caplog): + bad_name_dvcyaml = deepcopy(dvcyaml) + bad_name_dvcyaml["artifacts"]["bad_name"] = {"type": "model", "path": "bad.pkl"} + + (tmp_dir / "dvc.yaml").dump(bad_name_dvcyaml) + + artifacts = { + name: Artifact(**values) + for name, values in bad_name_dvcyaml["artifacts"].items() + } + + with caplog.at_level(logging.WARNING): + assert tmp_dir.dvc.artifacts.read() == {"dvc.yaml": artifacts} + assert "Can't use 'bad_name' as artifact name (ID)" in caplog.text + + def test_artifacts_add_subdir(tmp_dir, dvc): subdir = tmp_dir / "subdir" subdir.mkdir()