Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling for --open_pr #239

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sweagent/environment/swe_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sweagent.environment.utils import (
PROCESS_DONE_MARKER_END,
PROCESS_DONE_MARKER_START,
InvalidGithubURL,
copy_anything_to_container,
copy_file_to_container,
format_trajectory_markdown,
Expand Down Expand Up @@ -811,7 +812,11 @@ def open_pr(self, *, trajectory, _dry_run: bool=False):
# todo: have better way of handling this
# Adding random string suffix to avoid name conflicts if we had a previously failed run
issue_url = self.args.data_path
issue = get_gh_issue_data(issue_url, token=self._github_token)
try:
issue = get_gh_issue_data(issue_url, token=self._github_token)
except InvalidGithubURL as e:
msg = f"Data path must be a github issue URL if --open_pr is set."
raise ValueError(msg) from e
branch_name = f"swe-agent-fix-#{issue.number}-" + str(random.random())[2:10]

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