diff --git a/dvc/command/data_sync.py b/dvc/command/data_sync.py index d337245ce..a71417a7f 100644 --- a/dvc/command/data_sync.py +++ b/dvc/command/data_sync.py @@ -3,7 +3,6 @@ import os import dvc.cloud.base as cloud from dvc.command.common.base import CmdBase -from dvc.exceptions import DvcException class CmdDataBase(CmdBase): @@ -20,11 +19,12 @@ class CmdDataBase(CmdBase): ret = 1 return ret + class CmdDataPull(CmdDataBase): def do_run(self, target=None): try: self.project.pull(target=target, jobs=self.args.jobs) - except DvcException as exc: + except Exception as exc: self.project.logger.error('Failed to pull data from the cloud', exc) return 1 return 0 @@ -34,7 +34,7 @@ class CmdDataPush(CmdDataBase): def do_run(self, target=None): try: self.project.push(target=target, jobs=self.args.jobs) - except DvcException as exc: + except Exception as exc: self.project.logger.error('Failed to push data to the cloud', exc) return 1 return 0 @@ -44,7 +44,7 @@ class CmdDataFetch(CmdDataBase): def do_run(self, target=None): try: self.project.fetch(target=target, jobs=self.args.jobs) - except DvcException as exc: + except Exception as exc: self.project.logger.error('Failed to fetch data from the cloud', exc) return 1 return 0 @@ -72,7 +72,7 @@ class CmdDataStatus(CmdDataBase): try: status = self.project.status(target=target, jobs=self.args.jobs) self._show(status) - except DvcException as exc: + except Exception as exc: self.project.logger.error('Failed to obtain data status', exc) return 1 return 0 diff --git a/tests/test_cache.py b/tests/test_cache.py index 1d82fb3d1..5520b28b9 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -2,6 +2,7 @@ import os from dvc.cache import Cache from dvc.system import System +from dvc.output import Output from tests.basic_env import TestDvc @@ -42,3 +43,18 @@ class TestCache(TestDvc): self.assertEqual(len(cache), 2) self.assertEqual(cache, expected) + + +class TestCacheLoadBadDirCache(TestDvc): + def _do_test(self, ret): + self.assertTrue(isinstance(ret, list)) + self.assertEqual(len(ret), 0) + + def test(self): + fname = 'not-json' + self.create(fname, 'not,json') + self._do_test(Output.load_dir_cache(fname)) + + fname = 'not-list' + self.create(fname, '{"a": "b"}') + self._do_test(Output.load_dir_cache(fname)) diff --git a/tests/test_data_cloud.py b/tests/test_data_cloud.py index e59983553..b1e907e16 100644 --- a/tests/test_data_cloud.py +++ b/tests/test_data_cloud.py @@ -217,3 +217,16 @@ class TestDataCloudLocalCli(TestDvc): self.assertTrue(os.path.isfile(cache_dir)) self.main(['status']) + + +class TestDataCloudErrorCLI(TestDvc): + def main_fail(self, args): + ret = main(args) + self.assertNotEqual(ret, 0) + + def test_error(self): + f = 'non-existing-file' + self.main_fail(['status', f]) + self.main_fail(['push', f]) + self.main_fail(['pull', f]) + self.main_fail(['fetch', f])