Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Enh: Improved logging by using traceback.format_exc() (#787)

Manya Sharma0aef09972895
diff --git a/inspector/static.py b/inspector/static.py
index 31734335..6c58a48f 100644
--- a/inspector/static.py
+++ b/inspector/static.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import json
import logging
+import traceback
from argparse import ArgumentParser
from pathlib import Path
@@ -41,7 +42,7 @@ try:
STYLE_SHEET = infile.read()
except Exception as e:
style_file = Path(__file__).parent / "style.css"
- logger.error(f"Failed to load style sheet from {style_file}: {e}")
+ logger.error(f"Failed to load style sheet from {style_file}: {traceback.format_exc()}")
raise e
@@ -78,8 +79,8 @@ def _load_file(file_name, gold_patches, test_patches):
return history_content
else:
return "No history content found."
- except Exception as e:
- return f"Error loading content. {e}"
+ except Exception:
+ return f"Error loading content. {traceback.format_exc()}"
def _make_file_path_tree(file_path):
diff --git a/run.py b/run.py
index f1f9d6b4..16669d27 100644
--- a/run.py
+++ b/run.py
@@ -430,8 +430,8 @@ class Main:
logger.warning("**************************************************")
logger.warning("Found existing args.yaml with different arguments!")
logger.warning("**************************************************")
- except Exception as e:
- logger.warning(f"Failed to load existing args.yaml: {e}")
+ except Exception:
+ logger.warning(f"Failed to load existing args.yaml: {traceback.format_exc()}")
with log_path.open("w") as f:
self.args.dump_yaml(f)
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index 7e1b90b8..43e134fd 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -4,6 +4,7 @@ import copy
import json
import re
import time
+import traceback
from collections import defaultdict
from dataclasses import dataclass
from pathlib import Path
@@ -843,7 +844,7 @@ class Agent:
except KeyboardInterrupt:
raise
except Exception as e:
- self.logger.warning("Failed to set environment variables")
+ self.logger.warning(f"Failed to set environment variables: {traceback.format_exc()}")
raise e
command_files = list()
for file in self.config.command_files:
diff --git a/sweagent/agent/summarizer.py b/sweagent/agent/summarizer.py
index 0febbd8d..2394bbb8 100644
--- a/sweagent/agent/summarizer.py
+++ b/sweagent/agent/summarizer.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import tempfile
import textwrap
+import traceback
from abc import abstractmethod
from dataclasses import dataclass
from pathlib import Path
@@ -135,9 +136,9 @@ class SimpleSummarizer(SummarizeFunction):
return textwrap.dedent(self._warning_message.format(command_file_name=command_file_name)) + env.communicate(
f"open {command_file_name}"
), APIStats()
- except Exception as e:
+ except Exception:
self.logger.warning(
- f"Unhandled exception occurred when trying to summarize observation for input {input}: {e}"
+ f"Unhandled exception occurred when trying to summarize observation for input {input}: {traceback.format_exc()}"
)
return observation, APIStats()
@@ -235,8 +236,8 @@ class LMSummarizer(SummarizeFunction):
return textwrap.dedent(
self._warning_message_summarization_failed.format(command_file_name=command_file_name)
), APIStats()
- except Exception as e:
+ except Exception:
self.logger.warning(
- f"Unhandled exception occurred when trying to summarize observation for input {input}: {e}"
+ f"Unhandled exception occurred when trying to summarize observation for input {input}: {traceback.format_exc()}"
)
return observation, APIStats()
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 5f7f9686..61728bf8 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -729,8 +729,8 @@ class SWEEnv(gym.Env):
self.interactive_session.session_process.terminate()
except KeyboardInterrupt:
raise
- except Exception as e:
- self.logger.warning("Failed to stop interactive session: %s", str(e))
+ except Exception:
+ self.logger.warning("Failed to stop interactive session: %s", traceback.format_exc())
self.interactive_session = None
else:
self.logger.info("Interactive session stopped")
@@ -746,8 +746,8 @@ class SWEEnv(gym.Env):
assert self.container_name
try:
self.container_obj = docker.from_env().containers.get(self.container_name)
- except Exception as e:
- self.logger.warning(f"Failed to get fresh container object: {e}", exc_info=True)
+ except Exception:
+ self.logger.warning(f"Failed to get fresh container object: {traceback.format_exc()}", exc_info=True)
if self.container_obj.status not in {"paused", "exited", "dead", "stopping"}:
try:
self.container_obj.pause()