Exemplo n.º 1
0
def custom_exc(shell, etype, evalue, tb, tb_offset=None):
    '''this function will be called on exceptions in any cell
  '''
    # still show the error within the notebook, don't just swallow it
    shell.showtraceback((etype, evalue, tb), tb_offset=tb_offset)

    # initialize the formatter for making the tracebacks into strings
    itb = AutoFormattedTB(mode='Plain', tb_offset=1, color_scheme='NoColor')

    # grab the traceback and make it into a list of strings
    stb = itb.structured_traceback(etype, evalue, tb)
    sstb = itb.stb2text(stb)
    notify(sstb)
Exemplo n.º 2
0
 def structured_traceback(self,
                          type,
                          value,
                          tb,
                          tb_offset=None,
                          *args,
                          **kwargs):
     # If an offset is given, use it, else use the default
     offset = tb_offset if tb_offset else self.tb_offset
     ftb = AutoFormattedTB.structured_traceback(self, type, value, tb,
                                                offset, *args, **kwargs)
     if _traceback_verbose:
         return ftb
     else:
         length = vcsn_traceback_levels(tb)
         # Display the 2 header entries plus `length` entries
         # minus the entries that were offset, and the footer entry.
         return ftb[:2 + length - offset] + ftb[-1:]
Exemplo n.º 3
0
    def _render_traceback_(self):  # pragma: no cover
        """Render a minimized version of the `StateError` traceback.

        The default Jupyter/IPython traceback includes a lot of
        context from within `State` where the `StateError` is raised.
        This context isn't really needed, since the problem is almost certainly in
        the user code. This function removes the additional context.
        """
        if AutoFormattedTB is not None:
            a = AutoFormattedTB(mode="Context",
                                color_scheme="Neutral",
                                tb_offset=1)
            etype, evalue, tb = sys.exc_info()
            stb = a.structured_traceback(etype, evalue, tb, tb_offset=1)
            for i, line in enumerate(stb):
                if "site-packages" in line:
                    first_line = i
                    break
            return stb[:first_line] + stb[-1:]
Exemplo n.º 4
0
    def render_traceback(self):
        """Render a minimized version of the DimensionalityError traceback.

        The default Jupyter/IPython traceback includes a lot of
        context from within pint that actually raises the
        DimensionalityError. This context isn't really needed for
        this particular error, since the problem is almost certainly in
        the user code. This function removes the additional context.
        """
        a = AutoFormattedTB(mode="Context",
                            color_scheme="Neutral",
                            tb_offset=1)
        etype, evalue, tb = sys.exc_info()
        stb = a.structured_traceback(etype, evalue, tb, tb_offset=1)
        for i, line in enumerate(stb):
            if "site-packages" in line:
                first_line = i
                break
        return stb[:first_line] + stb[-1:]