Skip to content

Commit 6e1b200

Browse files
committed
fix: narrow exception handling in get_github_app_installation_token
## What/Why Narrow except clause from bare Exception to GithubException so that misconfiguration errors (bad int() cast, JWT construction failures) propagate instead of silently returning None and causing confusing 401s downstream. Addresses PR review feedback from @zkoppert. ## Proof it works All 14 tests in test_auth.py pass. Updated the request_failure test to raise GithubException instead of bare Exception to match the narrowed catch. Pylint clean (no new warnings). ## Risk + AI role Low. AI-generated (Claude Opus 4.6) with human review. ## Review focus Whether GithubException covers all the API/network error cases we want to catch, or if additional specific exceptions should be included. Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent a6cba0b commit 6e1b200

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""This is the module that contains functions related to authenticating to GitHub with a personal access token."""
22

33
import env
4-
from github import Auth, Github, GithubIntegration
4+
from github import Auth, Github, GithubException, GithubIntegration
55

66

77
def auth_to_github(
@@ -81,6 +81,6 @@ def get_github_app_installation_token(
8181
gi = GithubIntegration(auth=app_auth)
8282
installation_token = gi.get_access_token(int(gh_app_installation_id))
8383
return installation_token.token
84-
except Exception as e: # pylint: disable=broad-exception-caught
84+
except GithubException as e:
8585
print(f"Request failed: {e}")
8686
return None

test_auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest.mock import MagicMock, patch
55

66
import auth
7+
from github import GithubException
78

89

910
class TestAuth(unittest.TestCase):
@@ -262,7 +263,9 @@ def test_get_github_app_installation_token_request_failure(
262263
mock_app_auth_cls.return_value = mock_app_auth
263264
mock_gi = MagicMock()
264265
mock_gi_cls.return_value = mock_gi
265-
mock_gi.get_access_token.side_effect = Exception("Request failed")
266+
mock_gi.get_access_token.side_effect = GithubException(
267+
500, "Request failed", None
268+
)
266269

267270
result = auth.get_github_app_installation_token(
268271
ghe="https://api.github.com",

0 commit comments

Comments
 (0)