Exemple #1
0
 def from_exc_info(cls, artifact_name, exc_info):
     tb = Traceback(*exc_info)
     tb.filter_hidden_frames()
     return cls({
         'artifact': artifact_name,
         'exception': tb.exception,
         'traceback': tb.plaintext,
     })
Exemple #2
0
 def from_exc_info(cls, artifact_name, exc_info):
     tb = Traceback(*exc_info)
     tb.filter_hidden_frames()
     return cls({
         "artifact": artifact_name,
         "exception": tb.exception,
         "traceback": tb.plaintext,
     })
Exemple #3
0
 def from_exc_info(cls, artifact_name, exc_info):
     tb = Traceback(*exc_info)
     tb.filter_hidden_frames()
     return cls({
         'artifact': artifact_name,
         'exception': tb.exception,
         'traceback': tb.plaintext,
     })
Exemple #4
0
    def test_log(self):
        try:
            1 / 0
        except ZeroDivisionError:
            traceback = Traceback(*sys.exc_info())

        buffer_ = io.BytesIO() if PY2 else io.StringIO()
        traceback.log(buffer_)
        assert buffer_.getvalue().strip() == traceback.plaintext.strip()
Exemple #5
0
    def test_log(self):
        try:
            1 / 0
        except ZeroDivisionError:
            traceback = Traceback(*sys.exc_info())

        buffer_ = io.BytesIO() if PY2 else io.StringIO()
        traceback.log(buffer_)
        assert buffer_.getvalue().strip() == traceback.plaintext.strip()
Exemple #6
0
    def test_sourcelines_encoding(self):
        source = (u'# -*- coding: latin1 -*-\n\n'
                  u'def foo():\n'
                  u'    """höhö"""\n'
                  u'    1 / 0\n'
                  u'foo()').encode('latin1')
        code = compile(source, filename='lol.py', mode='exec')
        try:
            eval(code)
        except ZeroDivisionError:
            traceback = Traceback(*sys.exc_info())

        frames = traceback.frames
        assert len(frames) == 3
        assert frames[1].filename == 'lol.py'
        assert frames[2].filename == 'lol.py'

        class Loader(object):
            def get_source(self, module):
                return source

        frames[1].loader = frames[2].loader = Loader()
        assert frames[1].sourcelines == frames[2].sourcelines
        assert [line.code for line in frames[1].get_annotated_lines()] == \
            [line.code for line in frames[2].get_annotated_lines()]
        assert u'höhö' in frames[1].sourcelines[3]
Exemple #7
0
    def werkzeug_debug_traceback(self, exc_type, exc_value, tb):
        """ Munge the default Werkzeug traceback to include Mako info. """

        orig_type, orig_value, orig_tb = self.einfo
        translated = Traceback(orig_type, orig_value, tb)

        # Drop the "raise" frame from the traceback.
        translated.frames.pop()

        def orig_frames():
            cur = orig_tb
            while cur:
                yield cur
                cur = cur.tb_next

        # Append our original frames, overwriting previous source information
        # with the translated Mako line locators.
        for tb, record in zip(orig_frames(), self.records):
            name, line = record[4:6]
            if name:
                new_frame = MakoFrame(orig_type, orig_value, tb, name, line)
            else:
                new_frame = Frame(orig_type, orig_value, tb)

            translated.frames.append(new_frame)

        return translated
Exemple #8
0
    def test_sourcelines_encoding(self):
        source = ("# -*- coding: latin1 -*-\n\n"
                  "def foo():\n"
                  '    """höhö"""\n'
                  "    1 / 0\n"
                  "foo()").encode("latin1")
        code = compile(source, filename="lol.py", mode="exec")
        try:
            eval(code)
        except ZeroDivisionError:
            traceback = Traceback(*sys.exc_info())

        frames = traceback.frames
        assert len(frames) == 3
        assert frames[1].filename == "lol.py"
        assert frames[2].filename == "lol.py"

        class Loader:
            def get_source(self, module):
                return source

        frames[1].loader = frames[2].loader = Loader()
        assert frames[1].sourcelines == frames[2].sourcelines
        assert [line.code for line in frames[1].get_annotated_lines()
                ] == [line.code for line in frames[2].get_annotated_lines()]
        assert "höhö" in frames[1].sourcelines[3]
Exemple #9
0
 def render_template_into(self, template_name, this, fail=False,
                          **extra):
     """Renders a template into the artifact.  The default behavior is to
     catch the error and render it into the template with a failure marker.
     """
     try:
         rv = self.build_state.env.render_template(
             template_name, self.build_state.pad,
             this=this, **extra)
     except Exception:
         if fail:
             raise
         tb = Traceback(*sys.exc_info())
         rv = tb.render_full()
         self.set_dirty_flag()
     with self.open('wb') as f:
         f.write(rv.encode('utf-8') + b'\n')
Exemple #10
0
def test_non_hashable_exception():
    class MutableException(ValueError):
        __hash__ = None

    try:
        raise MutableException()
    except MutableException:
        # previously crashed: `TypeError: unhashable type 'MutableException'`
        Traceback(*sys.exc_info())
Exemple #11
0
 def __exit__(self, exc_type, exc_value, traceback):
     if exc_type:
         from werkzeug.debug.tbtools import Traceback
         logger.exception('could not load app code:')
         self._main = None
         tb = Traceback(exc_type, exc_value, traceback)
         self.exception = tb
         self._files.update(frame.filename for frame in tb.frames
                            if frame and frame.filename)
     # end if
     return True  # suppress the exception  # https://docs.python.org/3/whatsnew/2.6.html#writing-context-managers
Exemple #12
0
def test_chained_exception_cycle():
    try:
        try:
            raise ValueError()
        except ValueError:
            raise TypeError()
    except TypeError as e:
        # create a cycle and make it available outside the except block
        e.__context__.__context__ = error = e

    # if cycles aren't broken, this will time out
    tb = Traceback(TypeError, error, error.__traceback__)
    assert len(tb.groups) == 2
Exemple #13
0
    def test_filename_encoding(self, tmpdir, monkeypatch):
        moduledir = tmpdir.mkdir("föö")
        moduledir.join("bar.py").write("def foo():\n    1/0\n")
        monkeypatch.syspath_prepend(str(moduledir))

        import bar

        try:
            bar.foo()
        except ZeroDivisionError:
            traceback = Traceback(*sys.exc_info())

        assert "föö" in "\n".join(frame.render() for frame in traceback.frames)
Exemple #14
0
    def test_10_publish(self):
        """Test direct exception publishing.
        """
        self.app = self.create_application()

        try:
            raise ValueError
        except ValueError:
            type, exception, traceback = exc_info()
            traceback = Traceback(type, exception, traceback)

        data = json.loads(Exceptional.publish(self.app.config, traceback))
        exception = data["exception"]
        assert exception["exception_class"] == ValueError.__name__
Exemple #15
0
 def render_failure(self, exc_info):
     tb = Traceback(*exc_info)
     return tb.render_full()
Exemple #16
0
 def render_failure(self, exc_info):
     tb = Traceback(*exc_info)
     return tb.render_full()