diff --git a/src/psrt_ghsa_bot/app.py b/src/psrt_ghsa_bot/app.py index 9709302..3c93ab7 100644 --- a/src/psrt_ghsa_bot/app.py +++ b/src/psrt_ghsa_bot/app.py @@ -14,6 +14,7 @@ from dotenv import load_dotenv from githubkit import AppAuthStrategy, GitHub from githubkit.exception import RequestFailed, RequestError +from requests.exceptions import RequestException from psrt_ghsa_bot._sentry_monitoring import ( MONITOR_SLUG_GHSA, @@ -213,7 +214,7 @@ def iter_cve_refs_with_tags(cve_api: CveApi, cve_id: str, tags: set[str]) -> abc cve = cve_api.show_cve_record(cve_id) cve_state = cve["cveMetadata"]["state"] cve_refs = cve["containers"]["cna"]["references"] - except KeyError, RequestFailed, TypeError: + except KeyError, RequestException, TypeError: # If we got a bad response, we can still proceed with other updates. # Record the failure and continue. # Note TypeError covers tests where cve_api is a mock without a diff --git a/tests/test_app.py b/tests/test_app.py index 3e58a0d..0bc777a 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -5,6 +5,7 @@ from unittest import mock import pytest +import requests.exceptions as req_exc from psrt_ghsa_bot import app @@ -549,3 +550,20 @@ def test_only_draft_ghsa_closed_on_cve(show_cve_response, state) -> None: pass # We're testing the state didn't change, so no update is good. else: assert new_state == state + + +@pytest.mark.parametrize( + "errcls", + [ + req_exc.RequestException, + req_exc.HTTPError, + req_exc.ConnectionError, + req_exc.ConnectTimeout, + req_exc.ReadTimeout, + ], +) +def test_show_cve_errors_ignored(errcls, cve_id): + cve_api = mock.Mock() + cve_api.show_cve_record.side_effect = errcls("test error") + assert list(app.iter_cve_refs_with_tags(cve_api, cve_id, {"patch"})) == [] + cve_api.show_cve_record.assert_called()