Skip to content

Commit 27441b7

Browse files
committed
Crash when an release asset doesn't exist
Currently, the script crashes whenever a release asset is unable to download (for example a 404 response). This change instead logs the failure and allows the script to continue. No retry logic is enabled, but at least it prevents the crash and allows the backup to complete. Retry logic can be implemented later if wanted. closes josegonzalez#129
1 parent fac8e42 commit 27441b7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

bin/github-backup

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,27 @@ def download_file(url, path, auth):
569569
request.add_header('Accept', 'application/octet-stream')
570570
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
571571
opener = build_opener(S3HTTPRedirectHandler)
572-
response = opener.open(request)
573572

574-
chunk_size = 16 * 1024
575-
with open(path, 'wb') as f:
576-
while True:
577-
chunk = response.read(chunk_size)
578-
if not chunk:
579-
break
580-
f.write(chunk)
573+
try:
574+
response = opener.open(request)
575+
576+
chunk_size = 16 * 1024
577+
with open(path, 'wb') as f:
578+
while True:
579+
chunk = response.read(chunk_size)
580+
if not chunk:
581+
break
582+
f.write(chunk)
583+
except HTTPError as exc:
584+
# Gracefully handle 404 responses (and others) when downloading from S3
585+
log_info('Skipping download of asset {0} due to HTTPError: {1}'.format(url, exc.reason))
586+
except URLError as e:
587+
# Gracefully hadnle other URL errors
588+
log_info('Skipping download of asset {0} due to URLError: {1}'.format(url, e.reason))
589+
except socket.error as e:
590+
# Gracefully handle socket errors
591+
# TODO: Implement retry logic
592+
log_info('Skipping download of asset {0} due to socker error: {1}'.format(url, e.strerror))
581593

582594

583595
def get_authenticated_user(args):

0 commit comments

Comments
 (0)