mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Merge pull request #348 from hobarrera/nonexistant-pair-message
Add prettier message when syncing inexistent pair
This commit is contained in:
commit
8b13a932b8
4 changed files with 24 additions and 1 deletions
|
|
@ -44,6 +44,13 @@ def test_simple_run(tmpdir, runner):
|
||||||
assert tmpdir.join('path_b/haha.txt').read() == 'UID:haha'
|
assert tmpdir.join('path_b/haha.txt').read() == 'UID:haha'
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_inexistant_pair(tmpdir, runner):
|
||||||
|
runner.write_with_general("")
|
||||||
|
result = runner.invoke(['sync', 'foo'])
|
||||||
|
assert result.exception
|
||||||
|
assert 'pair foo does not exist.' in result.output.lower()
|
||||||
|
|
||||||
|
|
||||||
def test_debug_connections(tmpdir, runner):
|
def test_debug_connections(tmpdir, runner):
|
||||||
runner.write_with_general(dedent('''
|
runner.write_with_general(dedent('''
|
||||||
[pair my_pair]
|
[pair my_pair]
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,10 @@ class Config(object):
|
||||||
return expand_fetch_params(args)
|
return expand_fetch_params(args)
|
||||||
|
|
||||||
def get_pair(self, pair_name):
|
def get_pair(self, pair_name):
|
||||||
|
try:
|
||||||
return PairConfig(self, pair_name, *self.pairs[pair_name])
|
return PairConfig(self, pair_name, *self.pairs[pair_name])
|
||||||
|
except KeyError as e:
|
||||||
|
raise exceptions.PairNotFound(e, pair_name=pair_name)
|
||||||
|
|
||||||
|
|
||||||
class PairConfig(object):
|
class PairConfig(object):
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ class JobFailed(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Making this a decorator would be nice
|
||||||
def handle_cli_error(status_name=None):
|
def handle_cli_error(status_name=None):
|
||||||
'''
|
'''
|
||||||
Print a useful error message for the current exception.
|
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):
|
except (click.Abort, KeyboardInterrupt, JobFailed):
|
||||||
pass
|
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:
|
except Exception as e:
|
||||||
if status_name:
|
if status_name:
|
||||||
msg = 'Unhandled exception occured for {}.'.format(
|
msg = 'Unhandled exception occured for {}.'.format(
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,12 @@ class CollectionNotFound(Error):
|
||||||
'''Collection not found'''
|
'''Collection not found'''
|
||||||
|
|
||||||
|
|
||||||
|
class PairNotFound(Error):
|
||||||
|
'''Pair not found'''
|
||||||
|
|
||||||
|
pair_name = None
|
||||||
|
|
||||||
|
|
||||||
class PreconditionFailed(Error):
|
class PreconditionFailed(Error):
|
||||||
'''
|
'''
|
||||||
- The item doesn't exist although it should
|
- The item doesn't exist although it should
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue