From 7ed4fd384059ea881736b7df8a86bd78415fef87 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Mon, 6 Jan 2020 23:40:00 -0600 Subject: [PATCH 1/2] py3: use format_exc instead of print_exception --- dvc/logger.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/dvc/logger.py b/dvc/logger.py index e9b8f9c6af..4a2919ce8c 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -1,6 +1,6 @@ """Manages logging configuration for dvc repo.""" -import io +import traceback import logging.config import logging.handlers @@ -101,14 +101,8 @@ def _description(self, message, exception): return description.format(message=message, exception=exception) def _walk_exc(self, exc_info): - import traceback - - buffer = io.StringIO() - - traceback.print_exception(*exc_info, file=buffer) - exc = exc_info[1] - tb = buffer.getvalue() + tb = traceback.format_exc(*exc_info) exc_list = [str(exc)] tb_list = [tb] From f942e2645345dbaf0d60d09c70e52d09c76da058 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Tue, 7 Jan 2020 00:13:51 -0600 Subject: [PATCH 2/2] py3: remove tb_list --- dvc/logger.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dvc/logger.py b/dvc/logger.py index 4a2919ce8c..3afb0f647b 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -102,19 +102,14 @@ def _description(self, message, exception): def _walk_exc(self, exc_info): exc = exc_info[1] - tb = traceback.format_exc(*exc_info) exc_list = [str(exc)] - tb_list = [tb] - # NOTE: parsing chained exceptions. See dvc/exceptions.py for more info while hasattr(exc, "__cause__") and exc.__cause__: exc_list.append(str(exc.__cause__)) - if hasattr(exc, "cause_tb") and exc.cause_tb: - tb_list.insert(0, str(exc.cause_tb)) exc = exc.__cause__ - return exc_list, tb_list + return exc_list def _parse_exc(self, record): tb_only = getattr(record, "tb_only", False) @@ -122,7 +117,8 @@ def _parse_exc(self, record): if not record.exc_info: return (None, "") - exc_list, tb_list = self._walk_exc(record.exc_info) + exc_list = self._walk_exc(record.exc_info) + tb = traceback.format_exception(*record.exc_info) exception = None if tb_only else ": ".join(exc_list) @@ -133,7 +129,7 @@ def _parse_exc(self, record): red=colorama.Fore.RED, nc=colorama.Fore.RESET, line="-" * 60, - stack_trace="\n".join(tb_list), + stack_trace="".join(tb), ) else: stack_trace = ""