forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autogpt/forge): Send exception details in agent protocol endpoin…
…ts (Significant-Gravitas#7005) Send exception details in agent protocol endpoints Co-authored-by: Nicholas Tindle <[email protected]>
- Loading branch information
Showing
2 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import inspect | ||
import sys | ||
import traceback | ||
|
||
|
||
def get_exception_message(): | ||
"""Get current exception type and message.""" | ||
exc_type, exc_value, _ = sys.exc_info() | ||
exception_message = f"{exc_type.__name__}: {exc_value}" | ||
return exception_message | ||
|
||
|
||
def get_detailed_traceback(): | ||
"""Get current exception traceback with local variables.""" | ||
_, _, exc_tb = sys.exc_info() | ||
detailed_traceback = "Traceback (most recent call last):\n" | ||
formatted_tb = traceback.format_tb(exc_tb) | ||
detailed_traceback += "".join(formatted_tb) | ||
|
||
# Optionally add local variables to the traceback information | ||
detailed_traceback += "\nLocal variables by frame, innermost last:\n" | ||
while exc_tb: | ||
frame = exc_tb.tb_frame | ||
lineno = exc_tb.tb_lineno | ||
function_name = frame.f_code.co_name | ||
|
||
# Format frame information | ||
detailed_traceback += ( | ||
f" Frame {function_name} in {frame.f_code.co_filename} at line {lineno}\n" | ||
) | ||
|
||
# Get local variables for the frame | ||
local_vars = inspect.getargvalues(frame).locals | ||
for var_name, value in local_vars.items(): | ||
detailed_traceback += f" {var_name} = {value}\n" | ||
|
||
exc_tb = exc_tb.tb_next | ||
|
||
return detailed_traceback |