diff --git a/tests/cli/test_discover.py b/tests/cli/test_discover.py index 8395376..0d5a802 100644 --- a/tests/cli/test_discover.py +++ b/tests/cli/test_discover.py @@ -60,3 +60,24 @@ def test_discover_command(tmpdir, runner): .join('status') \ .join('foobar.collections') \ .read() + + +def test_discover_on_unsupported_storage(tmpdir, runner): + runner.write_with_general(dedent(''' + [storage foo] + type = http + url = https://example.com/foo.ics + + [storage bar] + type = memory + fileext = .txt + + [pair foobar] + a = foo + b = bar + collections = ["from a"] + ''').format(str(tmpdir))) + + result = runner.invoke(['discover']) + assert result.exception + assert 'doesn\'t support collection discovery' in result.output diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index 6e49d6a..950cfae 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -223,7 +223,14 @@ def _discover_from_config(config): cls, config = storage_class_from_config(config) try: - discovered = list(cls.discover(**config)) + try: + discovered = list(cls.discover(**config)) + except NotImplementedError: + raise exceptions.UserError( + 'The storage {} (type {}) doesn\'t support collection ' + 'discovery. You can only use `collections = null` with it.' + .format(config.get('instance_name', '???'), storage_type) + ) except Exception: return handle_storage_init_error(cls, config) else: