dvc: show "Having any troubles?" only on unexpected errors (#4496)

* dvc: dont catch generic exceptions

* dvc: show "Having any troubles?" only on unexpected errors

Fixes #4126
This commit is contained in:
Ruslan Kuprieiev
2020-08-30 21:08:12 +03:00
committed by GitHub
parent 1a35128457
commit fcbbfac7f8
5 changed files with 10 additions and 14 deletions
+1 -1
View File
@@ -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
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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
+4 -10
View File
@@ -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)
+1 -1
View File
@@ -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)])