Auto merge of #400 - pimutils:not-implemented-discovery, r=untitaker

Nicer output for unsupported discovery

Fix #347
This commit is contained in:
Homu 2016-04-03 06:49:52 +09:00
commit 45389f87d9
2 changed files with 29 additions and 1 deletions

View file

@ -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

View file

@ -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: