Skip to content

ui: don't show exception for "Too many files" error #3058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def format(self, record):
return record.msg

if record.levelname == "ERROR" or record.levelname == "CRITICAL":
exception, stack_trace = self._parse_exc(record.exc_info)
exception, stack_trace = self._parse_exc(record)

return (
"{color}{levelname}{nc}: {description}" "{stack_trace}\n"
Expand Down Expand Up @@ -122,13 +122,15 @@ def _walk_exc(self, exc_info):

return exc_list, tb_list

def _parse_exc(self, exc_info):
if not exc_info:
def _parse_exc(self, record):
tb_only = getattr(record, "tb_only", False)

if not record.exc_info:
return (None, "")

exc_list, tb_list = self._walk_exc(exc_info)
exc_list, tb_list = self._walk_exc(record.exc_info)

exception = ": ".join(exc_list)
exception = None if tb_only else ": ".join(exc_list)

if self._current_level() == logging.DEBUG:
stack_trace = (
Expand Down
3 changes: 2 additions & 1 deletion dvc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def main(argv=None):
except Exception as exc: # pylint: disable=broad-except
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
logger.exception(
"too many open files, please increase your `ulimit`"
"too many open files, please increase your `ulimit`",
extra={"tb_only": True},
)
else:
logger.exception("unexpected error")
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ def test_exception_under_verbose(self, caplog):

assert expected == formatter.format(caplog.records[0])

def test_tb_only(self, caplog):
with caplog.at_level(logging.DEBUG, logger="dvc"):
try:
raise Exception("description")
except Exception:
stack_trace = traceback.format_exc()
logger.exception("something", extra={"tb_only": True})

expected = (
"{red}ERROR{nc}: something\n"
"{red}{line}{nc}\n"
"{stack_trace}"
"{red}{line}{nc}\n".format(
line="-" * 60, stack_trace=stack_trace, **colors
)
)

assert expected == formatter.format(caplog.records[0])

def test_nested_exceptions(self, caplog):
with caplog.at_level(logging.DEBUG, logger="dvc"):
try:
Expand Down