Skip to content

Commit

Permalink
add: tweak stage overlap error message (#9514)
Browse files Browse the repository at this point in the history
* add: tweak stage overlap error message

* add: instructions for how to fix overlap error
  • Loading branch information
Dave Berenbaum authored Jun 1, 2023
1 parent 6543580 commit 6ace5ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down

0 comments on commit 6ace5ed

Please sign in to comment.