fix: use innermost traceback frame for error reporting

This commit is contained in:
Paul Gauthier (aider) 2024-08-29 13:10:55 -07:00
parent 96adf93cec
commit 725da4ba9f

View file

@ -77,19 +77,15 @@ def exception_handler(exc_type, exc_value, exc_traceback):
tb_text = "".join(tb_lines_with_basenames) tb_text = "".join(tb_lines_with_basenames)
# Find the first non-frozen frame # Find the innermost frame
while exc_traceback: innermost_tb = exc_traceback
filename = exc_traceback.tb_frame.f_code.co_filename while innermost_tb.tb_next:
if not filename.startswith("<frozen "): innermost_tb = innermost_tb.tb_next
break
exc_traceback = exc_traceback.tb_next
# Get the filename and line number # Get the filename and line number from the innermost frame
line_number = exc_traceback.tb_lineno filename = innermost_tb.tb_frame.f_code.co_filename
try: line_number = innermost_tb.tb_lineno
basename = os.path.basename(filename) basename = os.path.basename(filename)
except Exception:
basename = filename
# Get the exception type name # Get the exception type name
exception_type = exc_type.__name__ exception_type = exc_type.__name__