Skip to content

Commit c353809

Browse files
committed
Increase visibility of error message when action fails due to HTTP request error
The "arduino/report-size-deltas" action relies on the GitHub REST API. It makes HTTP requests to various API endpoints during each workflow run. These requests might produce an exception due to transient network outages, misconfiguration of the workflow, or a problem with the action. This will cause the action's step in the workflow run to fail. The maintainer of the repository in which the action is used may then need to investigate the cause of the failure. Previously, the cause of the failure could only be determined by evaluating the workflow run logs, which are somewhat unfriendly due to containing the Python stack trace produced by the HTTP request exception. The significant error message is hereby made visible as an annotation on the workflow run summary page through the use of an "error" workflow command.
1 parent 2537157 commit c353809

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

reportsizedeltas/reportsizedeltas.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -630,19 +630,26 @@ def raw_http_request(self, url: str, data: bytes | None = None):
630630
request = urllib.request.Request(url=url, headers=headers, data=data)
631631

632632
retry_count = 0
633-
while retry_count <= maximum_urlopen_retries:
634-
retry_count += 1
633+
while True:
635634
try:
636635
# The rate limit API is not subject to rate limiting
637636
if url.startswith("https://api.github.com") and not url.startswith("https://api.github.com/rate_limit"):
638637
self.handle_rate_limiting()
639638
return urllib.request.urlopen(url=request)
640639
except urllib.error.HTTPError as exception:
641-
if not determine_urlopen_retry(exception=exception):
642-
raise exception
640+
if determine_urlopen_retry(exception=exception):
641+
if retry_count < maximum_urlopen_retries:
642+
retry_count += 1
643+
continue
644+
else:
645+
# Maximum retries reached without successfully opening URL
646+
print("Maximum number of URL load retries exceeded")
647+
648+
print(f"::error::{exception.__class__.__name__}: {exception}")
649+
for line in exception.fp:
650+
print(line.decode(encoding="utf-8", errors="ignore"))
643651

644-
# Maximum retries reached without successfully opening URL
645-
raise TimeoutError("Maximum number of URL load retries exceeded")
652+
raise exception
646653

647654
def handle_rate_limiting(self) -> None:
648655
"""Check whether the GitHub API request limit has been reached.

reportsizedeltas/tests/test_reportsizedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def test_raw_http_request(mocker):
910910

911911
# urllib.request.urlopen() has potentially recoverable exceptions, but exceeds retry count
912912
reportsizedeltas.determine_urlopen_retry.return_value = True
913-
with pytest.raises(expected_exception=TimeoutError):
913+
with pytest.raises(expected_exception=urllib.error.HTTPError):
914914
report_size_deltas.raw_http_request(url=url, data=data)
915915

916916

0 commit comments

Comments
 (0)