From 1763607a883750f0e897949b55351abf6c7e68ef Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Thu, 26 Sep 2019 19:49:26 -0500 Subject: [PATCH 1/3] py2: display friendly error when raising a UnicodeError --- dvc/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dvc/main.py b/dvc/main.py index 4c55862bf..8cfaded3a 100644 --- a/dvc/main.py +++ b/dvc/main.py @@ -10,6 +10,7 @@ from dvc.config import ConfigError from dvc.analytics import Analytics from dvc.exceptions import NotDvcRepoError, DvcParserError from dvc.remote.pool import close_pools +from dvc.utils.compat import is_py2 logger = logging.getLogger("dvc") @@ -53,6 +54,15 @@ def main(argv=None): ret = 253 except DvcParserError: ret = 254 + except UnicodeError: + if is_py2: + logger.exception( + "unicode is not fully supported in DVC for Python 2.\n" + "Python 2.7 will not be maintained past 2020.\n" + "Please upgrade to Python 3 to work correctly with unicode.\n" + "Exception" + ) + ret = 255 except Exception: # pylint: disable=broad-except logger.exception("unexpected error") ret = 255 From 0bdad65f04ee2c3a08999989a5722fb295a4b242 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 27 Sep 2019 14:18:08 -0500 Subject: [PATCH 2/3] main: make sure to raise UinocedeError for py3 --- dvc/main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dvc/main.py b/dvc/main.py index 8cfaded3a..998ff1644 100644 --- a/dvc/main.py +++ b/dvc/main.py @@ -55,13 +55,12 @@ def main(argv=None): except DvcParserError: ret = 254 except UnicodeError: - if is_py2: - logger.exception( - "unicode is not fully supported in DVC for Python 2.\n" - "Python 2.7 will not be maintained past 2020.\n" - "Please upgrade to Python 3 to work correctly with unicode.\n" - "Exception" - ) + if not is_py2: + raise + logger.exception( + "unicode is not supported in DVC for Python 2" + " (end-of-life January 1, 2020), please upgrade to Python 3" + ) ret = 255 except Exception: # pylint: disable=broad-except logger.exception("unexpected error") From 39dc79b4186201382e74ca8a2925ec3ee1b8ceaa Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Fri, 27 Sep 2019 18:18:40 -0500 Subject: [PATCH 3/3] main: fix UnicodeError misplacement --- dvc/main.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/dvc/main.py b/dvc/main.py index 998ff1644..6cb11baef 100644 --- a/dvc/main.py +++ b/dvc/main.py @@ -54,16 +54,14 @@ def main(argv=None): ret = 253 except DvcParserError: ret = 254 - except UnicodeError: - if not is_py2: - raise - logger.exception( - "unicode is not supported in DVC for Python 2" - " (end-of-life January 1, 2020), please upgrade to Python 3" - ) - ret = 255 - except Exception: # pylint: disable=broad-except - logger.exception("unexpected error") + except Exception as exc: # pylint: disable=broad-except + if isinstance(exc, UnicodeError) and is_py2: + logger.exception( + "unicode is not supported in DVC for Python 2 " + "(end-of-life January 1, 2020), please upgrade to Python 3" + ) + else: + logger.exception("unexpected error") ret = 255 finally: logger.setLevel(outerLogLevel)