add: tweak stage overlap error message (#9514)

* add: tweak stage overlap error message

* add: instructions for how to fix overlap error
This commit is contained in:
Dave Berenbaum
2023-06-02 00:46:55 +03:00
committed by GitHub
parent 6543580100
commit 6ace5ed380
2 changed files with 15 additions and 2 deletions
+10 -1
View File
@@ -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(
+5 -1
View File
@@ -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")