diff --git a/dvc/command/destroy.py b/dvc/command/destroy.py index b3ec993d1..5f9dee6bd 100644 --- a/dvc/command/destroy.py +++ b/dvc/command/destroy.py @@ -25,7 +25,7 @@ class CmdDestroy(CmdBase): ) self.repo.destroy() - except Exception: # noqa, pylint: disable=broad-except + except DvcException: logger.exception("failed to destroy DVC") return 1 return 0 diff --git a/dvc/command/install.py b/dvc/command/install.py index 612fdd609..85b71fae4 100644 --- a/dvc/command/install.py +++ b/dvc/command/install.py @@ -2,6 +2,7 @@ import argparse import logging from dvc.command.base import CmdBase, append_doc_link +from dvc.exceptions import DvcException logger = logging.getLogger(__name__) @@ -10,7 +11,7 @@ class CmdInstall(CmdBase): def run(self): try: self.repo.install(self.args.use_pre_commit_tool) - except Exception: # noqa, pylint:disable=broad-except + except DvcException: logger.exception("failed to install DVC Git hooks") return 1 return 0 diff --git a/dvc/command/status.py b/dvc/command/status.py index c0d67fbcc..54711caf8 100644 --- a/dvc/command/status.py +++ b/dvc/command/status.py @@ -1,6 +1,7 @@ import logging from dvc.command.data_sync import CmdDataBase +from dvc.exceptions import DvcException logger = logging.getLogger(__name__) @@ -63,7 +64,7 @@ class CmdDataStatus(CmdDataBase): else: logger.info(self.UP_TO_DATE_MSG) - except Exception: # noqa, pylint: disable=broad-except + except DvcException: logger.exception("failed to obtain data status") return 1 return 0 diff --git a/dvc/main.py b/dvc/main.py index 49d0a73b8..5a1846d76 100644 --- a/dvc/main.py +++ b/dvc/main.py @@ -87,8 +87,9 @@ def main(argv=None): # noqa: C901 except DvcException: ret = 255 logger.exception("") - except OSError as exc: - if exc.errno == errno.EMFILE: + except Exception as exc: # noqa, pylint: disable=broad-except + # pylint: disable=no-member + if isinstance(exc, OSError) and exc.errno == errno.EMFILE: logger.exception( "too many open files, please visit " "{} to see how to handle this " @@ -97,17 +98,10 @@ def main(argv=None): # noqa: C901 ) else: logger.exception("unexpected error") - ret = 255 - except Exception: # noqa, pylint: disable=broad-except - logger.exception("unexpected error") + logger.info(FOOTER) ret = 255 try: - if ret != 0 and ( - ret != 1 or getattr(args, "cmd", "") != "check-ignore" - ): - logger.info(FOOTER) - if analytics.is_enabled(): analytics.collect_and_send_report(args, ret) diff --git a/tests/func/test_check_ignore.py b/tests/func/test_check_ignore.py index 315d97251..e9750f436 100644 --- a/tests/func/test_check_ignore.py +++ b/tests/func/test_check_ignore.py @@ -63,7 +63,7 @@ def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, caplog): ) def test_check_ignore_error_args_cases(tmp_dir, dvc, args, caplog): assert main(["check-ignore"] + args) == 255 - assert ("Having any troubles?" in caplog.text) == ("-q" not in args) + assert "Having any troubles?" not in caplog.text @pytest.mark.parametrize("path,ret", [({"dir": {}}, 0), ({"dir": "files"}, 1)])