##// END OF EJS Templates
Allow custom tracebacks for exception types with a _render_traceback_() method.
Thomas Kluyver -
Show More
@@ -86,22 +86,6 b' from IPython.utils.traitlets import (Integer, CBool, CaselessStrEnum, Enum,'
86 86 from IPython.utils.warn import warn, error
87 87 import IPython.core.hooks
88 88
89 # FIXME: do this in a function to avoid circular dependencies
90 # A better solution is to remove IPython.parallel.error,
91 # and place those classes in IPython.core.error.
92
93 class RemoteError(Exception):
94 pass
95
96 def _import_remote_error():
97 global RemoteError
98 try:
99 from IPython.parallel.error import RemoteError
100 except:
101 pass
102
103 _import_remote_error()
104
105 89 #-----------------------------------------------------------------------------
106 90 # Globals
107 91 #-----------------------------------------------------------------------------
@@ -1735,10 +1719,6 b' class InteractiveShell(SingletonConfigurable):'
1735 1719 self.showsyntaxerror(filename)
1736 1720 elif etype is UsageError:
1737 1721 self.write_err("UsageError: %s" % value)
1738 elif issubclass(etype, RemoteError):
1739 # IPython.parallel remote exceptions.
1740 # Draw the remote traceback, not the local one.
1741 self._showtraceback(etype, value, value.render_traceback())
1742 1722 else:
1743 1723 if exception_only:
1744 1724 stb = ['An exception has occurred, use %tb to see '
@@ -1746,7 +1726,13 b' class InteractiveShell(SingletonConfigurable):'
1746 1726 stb.extend(self.InteractiveTB.get_exception_only(etype,
1747 1727 value))
1748 1728 else:
1749 stb = self.InteractiveTB.structured_traceback(etype,
1729 try:
1730 # Exception classes can customise their traceback - we
1731 # use this in IPython.parallel for exceptions occurring
1732 # in the engines. This should return a list of strings.
1733 stb = value._render_traceback_()
1734 except Exception:
1735 stb = self.InteractiveTB.structured_traceback(etype,
1750 1736 value, tb, tb_offset=tb_offset)
1751 1737
1752 1738 self._showtraceback(etype, value, stb)
@@ -190,9 +190,12 b' class RemoteError(KernelError):'
190 190 def __str__(self):
191 191 return "%s(%s)" % (self.ename, self.evalue)
192 192
193 def render_traceback(self):
193 def _render_traceback_(self):
194 194 """render traceback to a list of lines"""
195 195 return (self.traceback or "No traceback available").splitlines()
196
197 # Previous name retained for backwards compatibility.
198 render_traceback = _render_traceback_
196 199
197 200 def print_traceback(self, excid=None):
198 201 """print my traceback"""
General Comments 0
You need to be logged in to leave comments. Login now