Skip to content

Commit

Permalink
Improved error output on PY3
Browse files Browse the repository at this point in the history
Chaining of errors using "raise from" via future's wrapper was losing a
lot of debugging information, including traceback for the cause of the
error. Instead, we now use the real "raise from" on PY3 and only use
future's replication of it on PY2. This means that there'll be less good
debugging info on PY2, but that's not a priority anyway.
  • Loading branch information
markgw committed Sep 30, 2020
1 parent d0c86d2 commit 30f231e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/python/pimlico/core/modules/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from __future__ import unicode_literals

from future import standard_library
from future.utils import raise_from

from pimlico.utils.core import raise_from

standard_library.install_aliases()
from builtins import str
Expand All @@ -23,7 +24,7 @@
from io import StringIO
from tarfile import TarFile
from textwrap import wrap
from traceback import format_exc, format_tb
from traceback import format_exc, format_tb, format_exception

from datetime import datetime

Expand Down
18 changes: 18 additions & 0 deletions src/python/pimlico/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from builtins import object
from contextlib import contextmanager

from future.utils import raise_from as future_raise_from, PY3

import sys
import ast

Expand Down Expand Up @@ -220,3 +222,19 @@ def __get__(self, obj, cls):
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value


def raise_from(exc, cause):
"""
Like future's raise_from function. However, on Py3, just calls raise X from Y.
On Py2, defers to future's replacement.
This means that we get the full functionality of raise from on PY3, which
is our main priority. If you run on PY2, you get less debugging information
in some cases, but that's no reason to ruin the debugging information on PY3 too!
"""
if PY3:
raise exc from cause
else:
future_raise_from(exc, cause)

0 comments on commit 30f231e

Please sign in to comment.