Skip to content

Commit

Permalink
Fix Cloud-CV#12: Add clear and concise error messages for when the se…
Browse files Browse the repository at this point in the history
…rver is down(Cloud-CV#90)

* Server error

* Convert default URL to official Host URL

* Error handling in submissions

* Leaderboard URL

* Tests for phase 404

* Fix server error color pallete
  • Loading branch information
guyandtheworld authored and RishabhJain2018 committed Aug 19, 2018
1 parent 39d5611 commit 9c53205
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
27 changes: 18 additions & 9 deletions evalai/utils/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def display_challenges(url):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -93,7 +94,8 @@ def display_ongoing_challenge_list():
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -135,7 +137,8 @@ def get_participant_or_host_teams(url):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand All @@ -159,7 +162,8 @@ def get_participant_or_host_team_challenges(url, teams):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)
response = response.json()
challenges += response['results']
Expand Down Expand Up @@ -249,7 +253,8 @@ def display_challenge_details(challenge):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -293,7 +298,8 @@ def display_challenge_phase_list(challenge_id):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -363,7 +369,8 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -415,7 +422,8 @@ def display_challenge_phase_split_list(challenge_id):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

phase_splits = response.json()
Expand Down Expand Up @@ -461,7 +469,8 @@ def display_leaderboard(challenge_id, phase_split_id):
else:
echo(err)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down
11 changes: 8 additions & 3 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}):
fg="red", bold=True))
else:
echo(err)
if "input_file" in response.json():
echo(style(response.json()["input_file"][0], fg="red", bold=True))
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)
response = response.json()
echo(style("\nYour file {} with the ID {} is successfully submitted.\n".format(file.name, response["id"]),
Expand Down Expand Up @@ -113,7 +116,8 @@ def display_my_submission_details(challenge_id, phase_id, start_date, end_date):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

response = response.json()
Expand Down Expand Up @@ -161,7 +165,8 @@ def display_submission_details(submission_id):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)
response = response.json()

Expand Down
9 changes: 6 additions & 3 deletions evalai/utils/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def display_teams(is_host):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)
response = response.json()

Expand Down Expand Up @@ -105,7 +106,8 @@ def create_team(team_name, team_url, is_host):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

if response.status_code == 201:
Expand Down Expand Up @@ -146,7 +148,8 @@ def participate_in_a_challenge(challenge_id, participant_team_id):
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
echo(style("\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n", bold=True, fg="red"))
sys.exit(1)

if response.status_code == 201:
Expand Down
34 changes: 24 additions & 10 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ def test_display_participant_and_host_challenge_lists_for_http_error_404(self):
url = "{}{}".format(API_HOST_URL, URLS.host_teams.value)
assert response == self.expected.format(url)

@responses.activate
def test_display_challenge_phase_detail_for_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(challenge, ['10', 'phase', '20'])
response = result.output.rstrip()
url = "{}{}".format(API_HOST_URL, URLS.challenge_phase_detail.value)
expected = self.expected.format(url).format('10', '20')
assert response == expected

@responses.activate
def test_display_challenge_phase_list_for_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(challenge, ['10', 'phases'])
response = result.output.rstrip()
url = "{}{}".format(API_HOST_URL, URLS.challenge_phase_list.value)
expected = self.expected.format(url).format('10')
assert response == expected

@responses.activate
def test_display_participant_team_for_http_error_404(self):
runner = CliRunner()
Expand Down Expand Up @@ -537,7 +555,7 @@ def test_create_team_for_request_exception(self):
def test_participate_in_a_challenge_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenge, ['2', 'participate', '3'])
assert result.output.strip() == "..."
assert result.exit_code == 1

@responses.activate
def test_display_challenge_phase_list_for_request_exception(self):
Expand All @@ -555,7 +573,7 @@ def test_display_challenge_phase_detail_for_request_exception(self):
def test_display_my_submission_details_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenge, ['3', 'phase', '7', 'submissions'])
assert result.output.strip() == "..."
assert result.exit_code == 1

@responses.activate
def test_display_submission_details_for_request_exception(self):
Expand All @@ -571,26 +589,22 @@ def test_make_submission_for_request_exception(self):
f.write('1 2 3 4 5 6')

result = runner.invoke(challenge, ['1', 'phase', '2', 'submit', "--file", "test_file.txt"], input="N")
response = result.output.rstrip()
expected = "Do you want to include the Submission Details? [y/N]: N\n{}".format("...")
assert response == expected
assert result.exit_code == 1

@responses.activate
def test_display_challenge_phase_split_list_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenge, ['1', 'phase', '2', 'splits'])
response = result.output.strip()
assert response == "..."
assert result.exit_code == 1

@responses.activate
def test_display_leaderboard_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenge, ['2', 'leaderboard', '1'])
response = result.output.strip()
assert response == "..."
assert result.exit_code == 1

@responses.activate
def test_display_challenge_details_for_request_exception(self):
runner = CliRunner()
result = runner.invoke(challenge, ["1"])
assert result.output.strip() == "..."
assert result.exit_code == 1

0 comments on commit 9c53205

Please sign in to comment.