diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index e8622b34c..00395f592 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -135,7 +135,7 @@ class DataCloud: remote = self.get_remote(name=name, command=command) if remote.fs.version_aware or remote.worktree: - raise NoRemoteError( + raise RemoteConfigError( f"'{command}' is unsupported for cloud versioned remotes" ) if hash_name in LEGACY_HASH_NAMES: diff --git a/dvc/stage/cache.py b/dvc/stage/cache.py index b831ad509..e7d9b8c82 100644 --- a/dvc/stage/cache.py +++ b/dvc/stage/cache.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, List, Optional, Tuple from funcy import first from dvc import fs +from dvc.config import RemoteConfigError from dvc.exceptions import CollectCacheError, DvcException from dvc.utils import dict_sha256, relpath @@ -274,15 +275,21 @@ class StageCache: return ret def push(self, remote: Optional[str], odb: Optional["ObjectDB"] = None): - dest_odb = odb or self.repo.cloud.get_remote_odb( - remote, "push --run-cache", hash_name="md5-dos2unix" - ) + try: + dest_odb = odb or self.repo.cloud.get_remote_odb( + remote, "push --run-cache", hash_name="md5-dos2unix" + ) + except RemoteConfigError as e: + raise RunCacheNotSupported(e) from e return self.transfer(self.repo.cache.legacy, dest_odb) def pull(self, remote: Optional[str], odb: Optional["ObjectDB"] = None): - odb = odb or self.repo.cloud.get_remote_odb( - remote, "fetch --run-cache", hash_name="md5-dos2unix" - ) + try: + odb = odb or self.repo.cloud.get_remote_odb( + remote, "fetch --run-cache", hash_name="md5-dos2unix" + ) + except RemoteConfigError as e: + raise RunCacheNotSupported(e) from e return self.transfer(odb, self.repo.cache.legacy) def get_used_objs(self, used_run_cache, *args, **kwargs): diff --git a/tests/func/test_run_cache.py b/tests/func/test_run_cache.py index 10b619ae0..a8669e88b 100644 --- a/tests/func/test_run_cache.py +++ b/tests/func/test_run_cache.py @@ -4,7 +4,7 @@ import pytest from funcy import first from dvc.dvcfile import LOCK_FILE -from dvc.stage.cache import _get_stage_hash +from dvc.stage.cache import RunCacheNotSupported, _get_stage_hash from dvc.utils.fs import remove @@ -229,3 +229,15 @@ def test_restore_pull(tmp_dir, dvc, run_copy, mocker, local_remote): assert (tmp_dir / "bar").exists() assert not (tmp_dir / "foo").unlink() assert (tmp_dir / LOCK_FILE).exists() + + +def test_push_pull_unsupported(tmp_dir, dvc, mocker, run_copy): + tmp_dir.gen("foo", "foo") + run_copy("foo", "bar", name="copy-foo-bar") + mocker.patch.object( + dvc.cloud, "get_remote_odb", side_effect=RunCacheNotSupported("foo") + ) + with pytest.raises(RunCacheNotSupported): + dvc.push(run_cache=True) + with pytest.raises(RunCacheNotSupported): + dvc.pull(run_cache=True)