Skip to content

Commit

Permalink
Add some error handling that will output a formatted message.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcloud committed Dec 4, 2014
1 parent 130b793 commit 08d60c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sunlight/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ def main():
])
fn_args = [g.split(',') for g in args.grouped.get('_')[2:]]
fn_args = list(itertools.chain.from_iterable(fn_args))
resp = getattr(service, args.get(1))(*fn_args, **params)
try:
resp = getattr(service, args.get(1))(*fn_args, **params)
except Exception as e:
error_name = e.__class__.__name__ if e.__class__.__name__ != 'type' else 'Error'
puts_err(colored.red("{}:".format(error_name)))
with indent(4):
puts_err(colored.yellow(e.message.decode()))
return
meta = getattr(resp, '_meta', None)
if meta:
puts(colored.yellow(json.dumps(meta, indent=2)))
Expand Down

0 comments on commit 08d60c5

Please sign in to comment.