From 6ace5ed380b2f9e35ea0edc4e8ed5c48d576050b Mon Sep 17 00:00:00 2001 From: Dave Berenbaum Date: Thu, 1 Jun 2023 17:46:55 -0400 Subject: [PATCH] add: tweak stage overlap error message (#9514) * add: tweak stage overlap error message * add: instructions for how to fix overlap error --- dvc/repo/add.py | 11 ++++++++++- tests/func/test_add.py | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dvc/repo/add.py b/dvc/repo/add.py index 74f47be7e..19109c809 100644 --- a/dvc/repo/add.py +++ b/dvc/repo/add.py @@ -32,6 +32,12 @@ if TYPE_CHECKING: from dvc.stage import Stage +PIPELINE_TRACKED_UPDATE_FMT = ( + "cannot update {out!r}: overlaps with an output of {stage} in '{path}'.\n" + "Run the pipeline or use 'dvc commit' to force update it." +) + + class StageInfo(NamedTuple): stage: "Stage" output_exists: bool @@ -91,7 +97,10 @@ def get_or_create_stage( (out_obj,) = repo.find_outs_by_path(target, strict=False) stage = out_obj.stage if not stage.is_data_source: - raise DvcException(f"cannot update {out!r}: not a data source") + msg = PIPELINE_TRACKED_UPDATE_FMT.format( + out=out, stage=stage, path=stage.relpath + ) + raise DvcException(msg) return StageInfo(stage, output_exists=True) except OutputNotFoundError: stage = repo.stage.create( diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 48b255552..0ab55d62e 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -722,7 +722,11 @@ def test_add_optimization_for_hardlink_on_empty_files(tmp_dir, dvc, mocker): def test_try_adding_pipeline_tracked_output(tmp_dir, dvc, run_copy): tmp_dir.dvc_gen("foo", "foo") run_copy("foo", "bar", name="copy-foo-bar") - with pytest.raises(DvcException, match="cannot update 'bar': not a data source"): + msg = ( + "cannot update 'bar': overlaps with an output of stage: 'copy-foo-bar' in " + "'dvc.yaml'.\nRun the pipeline or use 'dvc commit' to force update it." + ) + with pytest.raises(DvcException, match=msg): dvc.add("bar")