Permalink
Browse files

Abstract out exception handling for tool shed API exceptions.

  • Loading branch information...
jmchilton committed Apr 30, 2015
1 parent 46b2524 commit b86fe1f07119b1c8e2b290318964732ede35b4ff
Showing with 19 additions and 21 deletions.
  1. +3 −15 planemo/commands/cmd_shed_upload.py
  2. +16 −6 planemo/shed.py
@@ -1,6 +1,5 @@
"""
"""
import json
import sys

import click
@@ -96,20 +95,9 @@ def __handle_upload(ctx, realized_repository, **kwds):
try:
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
except Exception as e:
if hasattr(e, "read"):
exception_content = e.read()
try:
# Galaxy passes nice JSON messages as their errors, which bioblend
# blindly returns. Attempt to parse those.
upstream_error = json.loads(exception_content)
error(upstream_error['err_msg'])
except Exception as e2:
error("Could not update %s" % realized_repository.name)
error(exception_content)
error(e2.read())
else:
error("Could not update %s" % realized_repository.name)
error(str(e))
message = shed.api_exception_to_message(e)
error("Could not update %s" % realized_repository.name)
error(message)
return -1
info("Repository %s updated successfully." % realized_repository.name)
return 0
@@ -788,13 +788,9 @@ def find_repository_id(self, ctx, tsi):
)
return repo_id
except Exception as e:
message = api_exception_to_message(e)
error("Could not update %s" % self.name)
try:
error(e.read())
except AttributeError:
# I've seen a case where the error couldn't be read, so now
# wrapped in try/except
error("Could not query for repository in toolshed")
error(message)
return None

def create(self, ctx, tsi):
@@ -819,6 +815,20 @@ def create(self, ctx, tsi):
return None


def api_exception_to_message(e):
message = str(e)
if hasattr(e, "read"):
message = e.read()
try:
# Galaxy passes nice JSON messages as their errors, which bioblend
# blindly returns. Attempt to parse those.
upstream_error = json.loads(message)
message = upstream_error['err_msg']
except Exception:
pass
return message


def _glob(path, pattern):
pattern = os.path.join(path, pattern)
if os.path.isdir(pattern):

0 comments on commit b86fe1f

Please sign in to comment.