Exception handling always shows path relative to cwd
@@ -83,6 +83,10 @@ def add_generator_file_to_tb(idx, tbelem):
return [(file, lineno, '...', line.strip()), tbelem]
+def simplify_traceback(orig_tb):
+ return [(rel if not rel.startswith('..') else t1, t2, t3, t4) for (t1, t2, t3, t4) in orig_tb for rel in [os.path.relpath(t1)]]
+
+
def print_with_backtrace((exc_type, exc, tb), file, is_tb_extracted = False):
if not pkgutil.find_loader('backtrace'):
raise
@@ -93,13 +97,14 @@ def print_with_backtrace((exc_type, exc, tb), file, is_tb_extracted = False):
tb = traceback.extract_tb(tb)
try:
- orig_tb = tb
+ orig_tb = simplify_traceback(tb)
tb = replace_genfile_in_tb(tb, file)
tb = [new_elem for idx, tbelem in enumerate(tb) for new_elem in add_generator_file_to_tb(idx, tbelem)]
- tb = [(rel if not rel.startswith('..') else t1, t2, t3, t4) for (t1, t2, t3, t4) in tb for rel in [os.path.relpath(t1)]]
except:
tb = orig_tb
+ tb = simplify_traceback(tb)
+
backtrace.hook(
tpe=exc_type,
value=exc,
