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: Raise unclassified exception; use from e (#464)
Kilian Lieretc69747dd47d9
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex d9aff994..774e76a5 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -131,8 +131,8 @@ class SWEEnv(gym.Env):self.commit_sha = repo.head.object.hexshaexcept KeyboardInterrupt:raise- except:- logger.warning("Failed to get commit hash for this repo")+ except Exception as e:+ logger.exception("Failed to get commit hash for this repo: %s", str(e))self._github_token: str = keys_config.get("GITHUB_TOKEN", "") # type: ignore@@ -416,6 +416,7 @@ class SWEEnv(gym.Env):return observation, 0, True, infoexcept Exception:observation += "\nEXECUTION FAILED OR COMMAND MALFORMED"+ logger.exception("Unknown exception")# Record submission and end episode if `submit` keyword foundsubmission = self.get_submission(observation)@@ -509,7 +510,9 @@ class SWEEnv(gym.Env):except docker.errors.DockerException as e:if "Error while fetching server API version" in str(e):msg = "Docker is not running. Please start Docker and try again."- raise RuntimeError(msg) from e+ else:+ msg = "Unknown docker exception occurred. Are you sure docker is running?"+ raise RuntimeError(msg) from etry:self.container_obj = client.containers.get(self.container_name)except docker.errors.NotFound:diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex e949e990..849230ca 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -708,12 +708,12 @@ def get_instances(# Attempt load from HF datasets as a last resorttry:return postproc_instance_list(load_dataset(file_path, split=split))- except:+ except Exception as e:msg = (f"Could not load instances from {file_path}. ""Please ensure --data_path is a GitHub URL, a SWE-bench HuggingFace dataset, or a JSON/JSONL file.")- raise ValueError(msg)+ raise ValueError(msg) from edef get_associated_commit_urls(org: str, repo: str, issue_number: str, *, token: str = "") -> list[str]: