Add prettier message when syncing inexistent pair

This commit is contained in:
Hugo Osvaldo Barrera 2016-02-27 22:57:15 -03:00
parent 0162a0c4b6
commit c66432e2ee
3 changed files with 17 additions and 1 deletions

View file

@ -217,7 +217,10 @@ class Config(object):
return expand_fetch_params(args)
def get_pair(self, pair_name):
return PairConfig(self, pair_name, *self.pairs[pair_name])
try:
return PairConfig(self, pair_name, *self.pairs[pair_name])
except KeyError as e:
raise exceptions.PairNotFound(e, pair_name=pair_name)
class PairConfig(object):

View file

@ -68,6 +68,7 @@ class JobFailed(RuntimeError):
pass
# TODO: Making this a decorator would be nice
def handle_cli_error(status_name=None):
'''
Print a useful error message for the current exception.
@ -118,6 +119,12 @@ def handle_cli_error(status_name=None):
)
except (click.Abort, KeyboardInterrupt, JobFailed):
pass
except exceptions.PairNotFound as e:
cli_logger.error(
'Pair {pair_name} does not exist. Please check your '
'configuration file and make sure you\'ve typed the pair name '
'correctly'.format(pair_name=e.pair_name)
)
except Exception as e:
if status_name:
msg = 'Unhandled exception occured for {}.'.format(

View file

@ -35,6 +35,12 @@ class CollectionNotFound(Error):
'''Collection not found'''
class PairNotFound(Error):
'''Pair not found'''
pair_name = None
class PreconditionFailed(Error):
'''
- The item doesn't exist although it should