Skip to content

Commit 7a234ba

Browse files
authored
Merge pull request josegonzalez#130 from einsteinx2/issue/129-fix-crash-on-release-asset-download-error
Crash when an release asset doesn't exist
2 parents 252c254 + cb0293c commit 7a234ba

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
@@ -573,15 +573,27 @@ def download_file(url, path, auth):
573573
request.add_header('Accept', 'application/octet-stream')
574574
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
575575
opener = build_opener(S3HTTPRedirectHandler)
576-
response = opener.open(request)
577576

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

586598

587599
def get_authenticated_user(args):

0 commit comments

Comments
 (0)