Skip to content

Commit b01777e

Browse files
authored
Better error handling for --open_pr (SWE-agent#239)
Closes SWE-agent#237
1 parent d35bd94 commit b01777e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sweagent/environment/swe_env.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from sweagent.environment.utils import (
2222
PROCESS_DONE_MARKER_END,
2323
PROCESS_DONE_MARKER_START,
24+
InvalidGithubURL,
2425
copy_anything_to_container,
2526
copy_file_to_container,
2627
format_trajectory_markdown,
@@ -811,7 +812,11 @@ def open_pr(self, *, trajectory, _dry_run: bool=False):
811812
# todo: have better way of handling this
812813
# Adding random string suffix to avoid name conflicts if we had a previously failed run
813814
issue_url = self.args.data_path
814-
issue = get_gh_issue_data(issue_url, token=self._github_token)
815+
try:
816+
issue = get_gh_issue_data(issue_url, token=self._github_token)
817+
except InvalidGithubURL as e:
818+
msg = f"Data path must be a github issue URL if --open_pr is set."
819+
raise ValueError(msg) from e
815820
branch_name = f"swe-agent-fix-#{issue.number}-" + str(random.random())[2:10]
816821

817822
self.communicate_with_handling(
@@ -840,6 +845,11 @@ def open_pr(self, *, trajectory, _dry_run: bool=False):
840845
# If `--repo_path` was specified with a different github URL, then the record will contain
841846
# the forking user
842847
assert self.record is not None
848+
if not self.record["repo_type"] == "github":
849+
# We already validated that `--data_path` is a github issue URL
850+
# so this is the only case where we can reach here
851+
msg = "--repo_path must point to a github URL if --open_pr is set"
852+
raise ValueError(msg)
843853
forker, _ = self.record["repo"].split("/")
844854
head = branch_name
845855
remote = "origin"

0 commit comments

Comments
 (0)