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]
Fix(agent): Catch UnidiffParseErrors
Kilian Lieret41813943b547
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 148c383b..2e446443 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -14,6 +14,7 @@ from simple_parsing.helpers.fields import fieldfrom swerex.exceptions import BashIncorrectSyntaxError, CommandTimeoutError, SwerexExceptionfrom tenacity import RetryErrorfrom typing_extensions import Self+from unidiff import UnidiffParseErrorfrom sweagent import __version__, get_agent_commit_hash, get_rex_commit_hash, get_rex_versionfrom sweagent.agent.action_sampler import AbstractActionSampler, ActionSamplerConfig@@ -684,7 +685,12 @@ class Agent:def _get_edited_files_with_context(self, patch: str) -> dict[str, str]:"""Get the edited files with context from the patch"""assert self._env is not None- pf = PatchFormatter(patch, read_method=self._env.read_file) if patch else None+ try:+ pf = PatchFormatter(patch, read_method=self._env.read_file) if patch else None+ except UnidiffParseError:+ self.logger.error("Failed to parse patch with unidiff. Some variables will be empty.")+ pf = None+ # We still need to populate the variablesout = {}for context_length in [30, 50, 70]:value = "Empty. No edited files found."