Example #1
0
    def test_traceback_info(self):
        def foo(x):
            try:
                exec 'y = 3; raise Exception()' in {}
            except:
                _, _, tb = sys.exc_info()
            return tb

        result = utils.traceback_info(foo(2))
        self.assertEqual(2, len(result))
        self.assertEqual('django_debugger.tests', result[0]['module_name'])
        self.assertTrue('django_debugger/tests.py' in result[0]['file_path'])
        self.assertEqual('foo', result[0]['function_name'])
        self.assertEqual('2', result[0]['local_vars']['x'])
        self.assertEqual('3', result[1]['global_vars']['y'])
Example #2
0
def view_traceback(request, traceback_hash):
    tb_and_exc = request.debugger_middleware_state.tracebacks\
                        .get_traceback(traceback_hash)
    if tb_and_exc is None:
        err_msg = 'No previously recorded exception'
        err_msg += 'trace matching traceback hash: ' + traceback_hash
        raise Exception(err_msg)

    traceback, exception = tb_and_exc

    ctx = {'traceback_hash': traceback_hash,
           'exception_header': utils.format_exception_header(exception),
           'traceback_info': utils.traceback_info(traceback)}

    response = render(request, 'django_debugger/view_traceback.html',
                      ctx, status=500)
    self_url_path = reverse('view_traceback', kwargs={'traceback_hash':
                                                          traceback_hash})
    self_url = request.build_absolute_uri(self_url_path)
    response['X-Debug-URL'] = self_url
    return response