Skip to content

Commit 4ef31d4

Browse files
fix: better exception handling frame
1 parent 5a1a5f4 commit 4ef31d4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

DocToolsLLM/DocToolsLLM.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import sys
99
import faulthandler
10+
import traceback
1011
import pdb
1112
import json
1213
import pyfiglet
@@ -130,7 +131,23 @@ def __init__(
130131
if debug:
131132
def handle_exception(exc_type, exc_value, exc_traceback):
132133
if not issubclass(exc_type, KeyboardInterrupt):
134+
def p(message: str) -> None:
135+
"print error, in red if possible"
136+
try:
137+
red(message)
138+
except Exception as err:
139+
print(message)
140+
p(exc_type)
141+
p(exc_value)
142+
[p(line) for line in traceback.format_tb(exc_traceback)]
143+
p("\n--verbose was used so opening debug console at the "
144+
"appropriate frame. Press 'c' to continue to the frame "
145+
"of this print.")
133146
pdb.post_mortem(exc_traceback)
147+
p("You are now in the exception handling frame.")
148+
breakpoint()
149+
sys.exit(1)
150+
134151
sys.excepthook = handle_exception
135152
faulthandler.enable()
136153

0 commit comments

Comments
 (0)