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

bug: add exception handling #62

Merged
merged 1 commit into from
Jul 21, 2023
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
29 changes: 25 additions & 4 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import os
from os.path import dirname, join
import sys
from typing import List, Union

import github3
Expand Down Expand Up @@ -66,7 +67,7 @@ def search_issues(
) -> List[github3.search.IssueSearchResult]: # type: ignore
"""
Searches for issues/prs/discussions in a GitHub repository that match
the given search query.
the given search query and handles errors related to GitHub API responses.

Args:
search_query (str): The search query to use for finding issues/prs/discussions.
Expand All @@ -80,9 +81,29 @@ def search_issues(

# Print the issue titles
issues = []
for issue in issues_iterator:
print(issue.title) # type: ignore
issues.append(issue)
try:
for issue in issues_iterator:
print(issue.title) # type: ignore
issues.append(issue)
except github3.exceptions.ForbiddenError:
print(
"You do not have permission to view this repository; Check you API Token."
)
sys.exit(1)
except github3.exceptions.NotFoundError:
print("The repository could not be found; Check the repository owner and name.")
sys.exit(1)
except github3.exceptions.ConnectionError:
print(
"There was a connection error; Check your internet connection or API Token."
)
sys.exit(1)
except github3.exceptions.AuthenticationFailed:
print("Authentication failed; Check your API Token.")
sys.exit(1)
except github3.exceptions.UnprocessableEntity:
print("The search query is invalid; Check the search query.")
sys.exit(1)

return issues

Expand Down