Skip to content

Commit

Permalink
Make error responses more detailed & verbose(#73)
Browse files Browse the repository at this point in the history
* Fix error responses in challenges

* Fix error responses in teams

* Fix conflicts
  • Loading branch information
guyandtheworld authored and RishabhJain2018 committed Jul 19, 2018
1 parent 2bc9c63 commit bd1936e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
5 changes: 3 additions & 2 deletions evalai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def main(ctx):
Welcome to the EvalAI CLI.
"""
if ctx.invoked_subcommand is None:
welcome_text = ("Welcome to the EvalAI CLI. Use evalai"
"--help for viewing all the options")
welcome_text = ("Welcome to the EvalAI CLI. Use evalai --help for viewing all the options\n"
"CHALLENGE and PHASE placeholders used throughout the CLI are"
" for challenge_id\nand phase_id of the challenges and phases.")
echo(welcome_text)


Expand Down
20 changes: 16 additions & 4 deletions evalai/utils/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def display_challenge_details(challenge):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nUse `evalai challenges` to fetch the active challenges.\n", fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -285,7 +286,9 @@ def display_challenge_phase_list(challenge_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nUse `evalai challenges` to fetch the active challenges.", fg="red", bold=True))
echo(style("\nUse `evalai challenge CHALLENGE phases` to fetch the active phases.\n", fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -351,7 +354,11 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -399,9 +406,14 @@ def display_challenge_phase_split_list(challenge_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"], fg="red", bold=True)))
echo(style("\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
except requests.exceptions.RequestException as err:
echo(err)
sys.exit(1)
Expand Down
17 changes: 14 additions & 3 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -100,7 +104,11 @@ def display_my_submission_details(challenge_id, phase_id, start_date, end_date):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down Expand Up @@ -145,7 +153,10 @@ def display_submission_details(submission_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}\n"
"\nUse `evalai challenge CHALLENGE phase PHASE submissions` "
"to view your submission.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down
6 changes: 5 additions & 1 deletion evalai/utils/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def participate_in_a_challenge(challenge_id, participant_team_id):
except requests.exceptions.HTTPError as err:
if (response.status_code in EVALAI_ERROR_CODES):
validate_token(response.json())
echo(style("Error: {}".format(response.json()["error"]), fg="red", bold=True))
echo(style("\nError: {}\n"
"\nUse `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai teams` to fetch your participant "
"teams.\n".format(response.json()["error"]),
fg="red", bold=True))
else:
echo(err)
sys.exit(1)
Expand Down
27 changes: 20 additions & 7 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def setup(self):
def test_display_submission_details_for_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(submission, ['9'])
response = result.output.rstrip()
assert response == self.expected
response = result.output.strip()
expected = "{}\n\n{}".format(self.expected, "Use `evalai challenge CHALLENGE "
"phase PHASE submissions` to view your submission.")
assert response == expected

@responses.activate
def test_make_submission_for_object_does_not_exist(self):
Expand All @@ -247,8 +249,12 @@ def test_make_submission_for_object_does_not_exist(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(self.expected)
response = result.output.strip()

expected = "Do you want to include the Submission Details? [y/N]: N\n\n{}".format(self.expected)
expected = "{}\n\n{}".format(expected, "Use `evalai challenges` to fetch the active challenges.")
expected = "{}\n\n{}".format(expected, "Use `evalai challenge CHALLENGE phases` "
"to fetch the active phases.")
assert response == expected


Expand Down Expand Up @@ -292,7 +298,9 @@ def test_participate_in_a_challenge_when_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(challenge, ['2', 'participate', '3'])
response = result.output.rstrip()
assert response == self.expected
expected = "\n{}\n\n{}".format(self.expected, "Use `evalai challenges` to fetch the active challenges.")
expected = "{}\n\n{}".format(expected, "Use `evalai teams` to fetch your participant teams.")
assert response == expected


class TestTeamsWhenTeamNameAlreadyExists(BaseTestClass):
Expand Down Expand Up @@ -338,14 +346,19 @@ def test_display_challenge_phase_list_for_object_does_not_exist(self):
runner = CliRunner()
result = runner.invoke(challenge, ['10', 'phases'])
response = result.output.rstrip()
assert response == self.expected
expected = "\n{}\n\n{}".format(self.expected, "Use `evalai challenges` to fetch the active challenges.\n"
"\nUse `evalai challenge CHALLENGE phases` to fetch the "
"active phases.")
assert response == expected

@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()
assert response == self.expected
expected = "\n{}\n\n{}".format(self.expected, "Use `evalai challenges` to fetch the active challenges.")
expected = "{}\n\n{}".format(expected, "Use `evalai challenge CHALLENGE phases` to fetch the active phases.")
assert response == expected


class TestGetParticipantOrHostTeamChallengesHTTPErrorRequests(BaseTestClass):
Expand Down

0 comments on commit bd1936e

Please sign in to comment.