diff --git a/openhands/resolver/resolve_issue.py b/openhands/resolver/resolve_issue.py index 63a9e40a05ba..a90c4fb2ce05 100644 --- a/openhands/resolver/resolve_issue.py +++ b/openhands/resolver/resolve_issue.py @@ -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: diff --git a/tests/unit/resolver/test_resolve_issues.py b/tests/unit/resolver/test_resolve_issues.py index 9dd43eff8258..ab42165642a4 100644 --- a/tests/unit/resolver/test_resolve_issues.py +++ b/tests/unit/resolver/test_resolve_issues.py @@ -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)