Skip to content

Commit

Permalink
Merge pull request #75 from erasche/outputs
Browse files Browse the repository at this point in the history
Attempt to parse json returned for toolshed errors
  • Loading branch information
jmchilton committed Feb 16, 2015
2 parents e1da169 + 382f588 commit 44e91da
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions planemo/commands/cmd_shed_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from planemo.io import error
from planemo.io import info
from planemo.io import shell
import json

import fnmatch
import os
Expand Down Expand Up @@ -102,22 +103,40 @@ def __handle_upload(ctx, path, **kwds):
message = kwds.get("message", None)
if message:
update_kwds["commit_message"] = message

repo_id = __find_repository(ctx, tsi, path, kwds)
if repo_id is None:
return -1

try:
repo_id = shed.find_repository_id(ctx, tsi, path, **kwds)
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
except Exception as e:
error("Could not update %s" % path)
exception_content = e.read()
try:
error(e.read())
except:
# I've seen a case where the error couldn't be read, so now
# wrapped in try/except
pass
upstream_error = json.loads(exception_content)
error(upstream_error['err_msg'])
except Exception as e2:
error("Could not update %s" % path)
error(exception_content)
error(e2.read())
return -1
info("Repository %s updated successfully." % path)


def __find_repository(ctx, tsi, path, **kwds):
"""Extracted into separate function to reduce complexity though it's not a
really sensible change since we now have to catch the error code separately
whenever we call this function elsewhere.
"""
try:
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
repo_id = shed.find_repository_id(ctx, tsi, path, **kwds)
return repo_id
except Exception as e:
error("Could not update %s" % path)
error(e.read())
return -1
info("Repository %s updated successfully." % path)
try:
error(e.read())
except Exception as e2:
# I've seen a case where the error couldn't be read, so now
# wrapped in try/except
error(e2.read())
return None

0 comments on commit 44e91da

Please sign in to comment.