How to use the pudb.lowlevel.format_exception function in pudb

To help you get started, we’ve selected a few pudb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inducer / pudb / pudb / debugger.py View on Github external
def show_exception_dialog(self, exc_tuple):
        from pudb.lowlevel import format_exception

        tb_txt = "".join(format_exception(exc_tuple))
        while True:
            res = self.dialog(
                    urwid.ListBox(urwid.SimpleListWalker([urwid.Text(
                        "The program has terminated abnormally because of "
                        "an exception.\n\n"
                        "A full traceback is below. You may recall this "
                        "traceback at any time using the 'e' key. "
                        "The debugger has entered post-mortem mode and will "
                        "prevent further state changes.\n\n"
                        + tb_txt)])),
                    title="Program Terminated for Uncaught Exception",
                    buttons_and_results=[
                        ("OK", True),
                        ("Save traceback", "save"),
                        ])
github inducer / pudb / pudb / debugger.py View on Github external
], title="Pick Module")
                self.last_module_filter = filt_edit.get_edit_text()

                if result is True:
                    widget, pos = lb.get_focus()
                    if widget is new_mod_entry:
                        new_mod_name = filt_edit.get_edit_text()
                        try:
                            __import__(str(new_mod_name))
                        except Exception:
                            from pudb.lowlevel import format_exception

                            self.message("Could not import module '%s':\n\n%s" % (
                                new_mod_name, "".join(
                                    format_exception(sys.exc_info()))),
                                title="Import Error")
                        else:
                            show_mod(__import__(str(new_mod_name)))
                            break
                    else:
                        show_mod(sys.modules[widget.base_widget.get_text()[0]])
                        break
                elif result is False:
                    break
                elif result == "reload":
                    widget, pos = lb.get_focus()
                    if widget is not new_mod_entry:
                        mod_name = widget.base_widget.get_text()[0]
                        mod = sys.modules[mod_name]
                        if PY3:
                            import importlib
github inducer / pudb / pudb / __init__.py View on Github external
import threading
    if not isinstance(threading.current_thread(), threading._MainThread):
        from warnings import warn
        # Setting signals from a non-main thread will not work
        return warn("Setting the interrupt handler can only be done on the main "
                "thread. The interrupt handler was NOT installed.")

    try:
        signal.signal(interrupt_signal, _interrupt_handler)
    except ValueError:
        from pudb.lowlevel import format_exception
        import sys
        from warnings import warn
        warn("setting interrupt handler on signal %d failed: %s"
                % (interrupt_signal, "".join(format_exception(sys.exc_info()))))
github inducer / pudb / pudb / debugger.py View on Github external
def show_traceback(w, size, key):
            if self.current_exc_tuple is not None:
                from pudb.lowlevel import format_exception

                result = self.dialog(
                        urwid.ListBox(urwid.SimpleListWalker([urwid.Text(
                            "".join(format_exception(self.current_exc_tuple)))])),
                        [
                            ("Close", "close"),
                            ("Location", "location")
                            ],
                        title="Exception Viewer",
                        focus_buttons=True,
                        bind_enter_esc=False)

                if result == "location":
                    self.debugger.set_frame_index(len(self.debugger.stack)-1)

            else:
                self.message("No exception available.")
github inducer / pudb / pudb / debugger.py View on Github external
if not exists(fn):
                            outf = open(fn, "w")
                            try:
                                outf.write(tb_txt)
                            finally:
                                outf.close()

                            self.message("Traceback saved as %s." % fn,
                                    title="Success")

                            break

                        n += 1

                except Exception:
                    io_tb_txt = "".join(format_exception(sys.exc_info()))
                    self.message(
                            "An error occurred while trying to write "
                            "the traceback:\n\n" + io_tb_txt,
                            title="I/O error")
github inducer / pudb / pudb / debugger.py View on Github external
breakpoints = debugger_ui.debugger.get_file_breaks(self.file_name)[:]
        breakpoints = [lineno for lineno in breakpoints if
            any(bp.enabled
                for bp in debugger_ui.debugger.get_breaks(self.file_name, lineno))]
        breakpoints += [i for f, i in debugger_ui.debugger.set_traces if f
            == self.file_name and debugger_ui.debugger.set_traces[f, i]]
        try:
            from linecache import getlines
            lines = getlines(self.file_name)
            return format_source(
                    debugger_ui, list(decode_lines(lines)), set(breakpoints))
        except Exception:
            from pudb.lowlevel import format_exception
            debugger_ui.message("Could not load source file '%s':\n\n%s" % (
                self.file_name, "".join(format_exception(sys.exc_info()))),
                title="Source Code Load Error")
            return [SourceLine(debugger_ui,
                "Error while loading '%s'." % self.file_name)]