From 0d1720eaf5a30e16834d94acf47bb4dcd5d978cc Mon Sep 17 00:00:00 2001 From: Aishwary_Jain Date: Sat, 23 Mar 2024 19:31:09 +0530 Subject: [PATCH] Handled Exceptions at potential points --- evalai/submissions.py | 44 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/evalai/submissions.py b/evalai/submissions.py index d1ddd8ae..29adce48 100644 --- a/evalai/submissions.py +++ b/evalai/submissions.py @@ -117,13 +117,43 @@ def push(image, phase, url, public, private): request_path = URLS.phase_details_using_slug.value request_path = request_path.format(phase) response = make_request(request_path, "GET") - challenge_pk = response.get("challenge") - phase_pk = response.get("id") + try: + challenge_pk = response.get("challenge") + except KeyError: + echo( + style( + "\nError: Key 'challenge' not found in response.", fg="red", bold=True + ) + ) + sys.exit(1) + try: + phase_pk = response.get("id") + except KeyError: + echo( + style( + "\nError: Key 'id' not found in response for phase details.", fg="red", bold=True + ) + ) + sys.exit(1) request_path = URLS.challenge_details.value request_path = request_path.format(challenge_pk) - response = make_request(request_path, "GET") - max_docker_image_size = response.get("max_docker_image_size") + try: + response = make_request(request_path, "GET") + except requests.exceptions.RequestException as err: + echo(err) + sys.exit(1) + try: + max_docker_image_size = response.get("max_docker_image_size") + except KeyError: + echo( + style( + "\nError: Key 'max_docker_image_size' not found in challenge details response.", + fg="red", + bold=True, + ) + ) + sys.exit(1) docker_image_size = docker_image.__dict__.get("attrs").get("VirtualSize") if docker_image_size > max_docker_image_size: @@ -137,7 +167,11 @@ def push(image, phase, url, public, private): request_path = URLS.get_aws_credentials.value request_path = request_path.format(phase_pk) - response = make_request(request_path, "GET") + try: + response = make_request(request_path, "GET") + except requests.exceptions.RequestException as err: + echo(err) + sys.exit(1) federated_user = response["success"]["federated_user"] repository_uri = response["success"]["docker_repository_uri"]