Skip to content

Commit

Permalink
cli: fix exception handling on file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Nov 16, 2020
1 parent b8baa41 commit 942d015
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 0.7.1 (2020-11-10)
--------------------------

- Changes ``ping`` command output to include REANA client and server version information.
- Fixes ``upload`` command to properly display errors.

Version 0.7.0 (2020-10-20)
--------------------------
Expand Down
13 changes: 6 additions & 7 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def upload_file(workflow_id, file_, file_name, access_token):
headers={"Content-Type": "application/octet-stream"},
verify=False,
)
return http_response.json()
if http_response.ok:
return http_response.json()
raise Exception(http_response.json().get("message"))
except requests.exceptions.ConnectionError:
logging.debug("File could not be uploaded.", exc_info=True)
raise Exception("Could not connect to the server {}".format(get_api_url()))
Expand All @@ -303,9 +305,7 @@ def upload_file(workflow_id, file_, file_name, access_token):
logging.debug(
"Something went wrong while connecting to the server.", exc_info=True
)
raise Exception(
"The request to the server has failed for an " "unknown reason."
)
raise Exception("The request to the server has failed for an unknown reason.")
except Exception as e:
raise e

Expand Down Expand Up @@ -525,9 +525,7 @@ def upload_to_server(workflow, paths, access_token):
logging.info("Uploading '{}' ...".format(fname))
try:
upload_file(workflow, f, save_path, access_token)
logging.info(
"File '{}' was successfully " "uploaded.".format(fname)
)
logging.info("File '{}' was successfully uploaded.".format(fname))
if symlink:
save_path = "symlink:{}".format(save_path)
return [save_path]
Expand All @@ -537,6 +535,7 @@ def upload_to_server(workflow, paths, access_token):
logging.info(
"Something went wrong while uploading {}".format(fname)
)
raise e


def get_workflow_parameters(workflow, access_token):
Expand Down
4 changes: 3 additions & 1 deletion reana_client/cli/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ def upload_files(ctx, workflow, filenames, access_token): # noqa: D301
logging.debug(str(e))
click.echo(
click.style(
"Something went wrong while uploading {}".format(filename),
"Something went wrong while uploading {}: \n{}".format(
filename, str(e)
),
fg="red",
),
err=True,
Expand Down

0 comments on commit 942d015

Please sign in to comment.