Skip to content

Commit

Permalink
Merge pull request #1118 from gpt-engineer-org/1110-hot-fix-for-resto…
Browse files Browse the repository at this point in the history
…ring-strack-trace

Improve Error Handling to Include Full Stack Trace
  • Loading branch information
viborc committed Apr 25, 2024
2 parents 7630560 + 95e2e7a commit 2a5546b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gpt_engineer/core/default/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io
import re
import sys
import traceback

from pathlib import Path
from typing import List, MutableMapping, Union
Expand Down Expand Up @@ -380,8 +381,9 @@ def handle_improve_mode(prompt, agent, memory, files_dict):
files_dict = agent.improve(files_dict, prompt)
except Exception as e:
print(
f"Error while improving the project: {e}\nCould you please upload the debug_log_file.txt in {memory.path} folder to github?"
f"Error while improving the project: {e}\nCould you please upload the debug_log_file.txt in {memory.path} folder to github?\nFULL STACK TRACE:\n"
)
traceback.print_exc(file=sys.stdout) # Print the full stack trace
finally:
# Reset stdout
sys.stdout = old_stdout
Expand Down
24 changes: 24 additions & 0 deletions tests/core/default/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
curr_fn,
gen_code,
gen_entrypoint,
handle_improve_mode,
improve_fn,
setup_sys_prompt,
setup_sys_prompt_existing_code,
Expand Down Expand Up @@ -310,3 +311,26 @@ def test_improve_existing_code(self, tmp_path):
}
)
assert improved_code == expected_code

def test_handle_improve_mode_multilayer_error_trace(self):
# Mock the AI class
class MockAI:
def improve(self, files_dict, prompt):
try:
raise Exception("This is a nested test exception")
except Exception as e:
raise Exception("This is a test exception") from e

agent = MockAI()
memory = DiskMemory(tempfile.mkdtemp())
files_dict = FilesDict({"main.py": "print('Hello, World!')"})
prompt = (
"Change the program to print 'Goodbye, World!' instead of 'Hello, World!'"
)

try:
handle_improve_mode(prompt, agent, memory, files_dict)
except Exception as e:
assert str(e) == "This is a test exception"
assert isinstance(e.__cause__, Exception)
assert str(e.__cause__) == "This is a nested test exception"

0 comments on commit 2a5546b

Please sign in to comment.