From 3da80e96e53a4fe97c95f0b74550a04de9638b8a Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Sat, 6 Aug 2022 22:34:25 -0400 Subject: [PATCH] Add hover stack trace on exception showing as attribute --- django_dump_die/templatetags/dump_die.py | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/django_dump_die/templatetags/dump_die.py b/django_dump_die/templatetags/dump_die.py index 1cc2268..0048041 100644 --- a/django_dump_die/templatetags/dump_die.py +++ b/django_dump_die/templatetags/dump_die.py @@ -560,13 +560,24 @@ def get_obj_values(obj): functions = [] # (attr, doc, access_modifier) try: - # Attempt to get member values of object. Falls back to empty list on failure. members = get_members(obj) except Exception as exception: # On exception, add exception to attributes and return the attributes. - attributes.append(['EXCEPTION', str(exception), None, 'empty', 'Exception']) + + # 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) + + # Add exception data to attributes and return. + attributes.append(['EXCEPTION', str(exception), None, 'empty', title]) return (attributes, functions) # Once all members have been collected, attempt to figure out what type, access modifier, css class, and title @@ -643,7 +654,18 @@ def get_obj_values(obj): attributes.append([attr, value, access_modifier, css_class, title]) except Exception as inner_exception: - attributes.append(['EXCEPTION', str(inner_exception), None, 'empty', 'Exception']) + # First get exception data. + tb = inner_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) + + # Add exception data to attributes and return. + attributes.append(['EXCEPTION', str(inner_exception), None, 'empty', title]) # Attempt to sort the functions and just ignore any errors. try: -- GitLab