Skip to content

Commit

Permalink
Improve error message when issue/PR not found in resolver (#5455)
Browse files Browse the repository at this point in the history
Co-authored-by: openhands <[email protected]>
  • Loading branch information
neubig and openhands-agent authored Dec 8, 2024
1 parent 2466d90 commit a7e4a7a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openhands/resolver/resolve_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ async def resolve_issue(
issue_numbers=[issue_number], comment_id=comment_id
)

if not issues:
raise ValueError(
f'No issues found for issue number {issue_number}. Please verify that:\n'
f'1. The issue/PR #{issue_number} exists in the repository {owner}/{repo}\n'
f'2. You have the correct permissions to access it\n'
f'3. The repository name is spelled correctly'
)

issue = issues[0]

if comment_id is not None:
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/resolver/test_resolve_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ def test_initialize_runtime():
)


@pytest.mark.asyncio
async def test_resolve_issue_no_issues_found():
from openhands.resolver.resolve_issue import resolve_issue

# Mock dependencies
mock_handler = MagicMock()
mock_handler.get_converted_issues.return_value = [] # Return empty list

with patch(
'openhands.resolver.resolve_issue.issue_handler_factory',
return_value=mock_handler,
):
with pytest.raises(ValueError) as exc_info:
await resolve_issue(
owner='test-owner',
repo='test-repo',
token='test-token',
username='test-user',
max_iterations=5,
output_dir='/tmp',
llm_config=LLMConfig(model='test', api_key='test'),
runtime_container_image='test-image',
prompt_template='test-template',
issue_type='pr',
repo_instruction=None,
issue_number=5432,
comment_id=None,
)

assert 'No issues found for issue number 5432' in str(exc_info.value)
assert 'test-owner/test-repo' in str(exc_info.value)
assert 'exists in the repository' in str(exc_info.value)
assert 'correct permissions' in str(exc_info.value)


def test_download_issues_from_github():
llm_config = LLMConfig(model='test', api_key='test')
handler = IssueHandler('owner', 'repo', 'token', llm_config)
Expand Down

0 comments on commit a7e4a7a

Please sign in to comment.