Nicer error message for InvalidResponse

See #448
This commit is contained in:
Markus Unterwaditzer 2016-05-12 18:38:41 +02:00
parent 45cea8f1f3
commit 4742ea61bc
3 changed files with 25 additions and 2 deletions

View file

@ -10,7 +10,9 @@ from hypothesis.strategies import (
text
)
from vdirsyncer.cli.utils import coerce_native
from vdirsyncer import exceptions
from vdirsyncer.cli.utils import coerce_native, handle_cli_error
@given(one_of(
@ -24,3 +26,14 @@ from vdirsyncer.cli.utils import coerce_native
))
def test_coerce_native_fuzzing(s):
coerce_native(s)
def test_handle_cli_error(capsys):
try:
raise exceptions.InvalidResponse('ayy lmao')
except:
handle_cli_error()
out, err = capsys.readouterr()
assert 'returned something vdirsyncer doesn\'t understand' in err
assert 'ayy lmao' in err

View file

@ -6,6 +6,7 @@ vdirsyncer is a synchronization tool for vdir. See the README for more details.
from __future__ import print_function
PROJECT_HOME = 'https://github.com/pimutils/vdirsyncer'
BUGTRACKER_HOME = PROJECT_HOME + '/issues'
DOCS_HOME = 'https://vdirsyncer.readthedocs.io/en/stable'
try:

View file

@ -16,7 +16,7 @@ import click
import click_threading
from . import cli_logger
from .. import DOCS_HOME, exceptions
from .. import BUGTRACKER_HOME, DOCS_HOME, exceptions
from ..sync import IdentConflict, StorageEmpty, SyncConflict
from ..utils import expand_path, get_storage_init_args
from ..utils.compat import to_native
@ -128,6 +128,15 @@ def handle_cli_error(status_name=None):
'configuration file and make sure you\'ve typed the pair name '
'correctly'.format(pair_name=e.pair_name)
)
except exceptions.InvalidResponse as e:
cli_logger.error(
'The server returned something vdirsyncer doesn\'t understand. '
'Error message: {!r}\n'
'While this is most likely a serverside problem, the vdirsyncer '
'devs are generally interested in such bugs. Please report it in '
'the issue tracker at {}'
.format(e, BUGTRACKER_HOME)
)
except Exception as e:
if status_name:
msg = 'Unhandled exception occured for {}.'.format(