From 2fa79be1823558df3d5c8bb5f85b8d3a68b29ef6 Mon Sep 17 00:00:00 2001 From: David Barnes <barnesdavidj@gmail.com> Date: Fri, 9 Sep 2022 13:08:33 -0400 Subject: [PATCH] Update the exception traceback handling to utilize more of the default traceback handling provided by Django as well as provide some additional information. --- django_dump_die/templatetags/dump_die.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/django_dump_die/templatetags/dump_die.py b/django_dump_die/templatetags/dump_die.py index b4d4ad7..e869bf6 100644 --- a/django_dump_die/templatetags/dump_die.py +++ b/django_dump_die/templatetags/dump_die.py @@ -3,6 +3,7 @@ # System Imports. import inspect import re +import traceback import types from decimal import Decimal @@ -569,13 +570,13 @@ def get_obj_values(obj): # First get exception data. tb = exception.__traceback__ - title = 'Exception:\n' - while tb is not None: - line_num = tb.tb_lineno - name = tb.tb_frame.f_code.co_name - filename = tb.tb_frame.f_code.co_filename - tb = tb.tb_next - title += '\n[ {0} : {1} ] {2}\n'.format(line_num, name, filename) + title = 'Exception Occurred\n\n' + title += f'Exception Type: {type(exception).__name__}\n' + title += f'Exception Value: {str(exception)}\n\n' + title += 'Traceback (most recent call last):\n\n' + for entry in traceback.format_tb(tb): + title += f'{entry}\n' + title += 'End of traceback' # Add exception data to attributes and return. attributes.append(['EXCEPTION', str(exception), None, 'empty', title]) -- GitLab