introduce custom UsageError

This is a exception to be thrown when the error occures because
of bad user data. We don't want to print a full stack trace in
these cases but just tell the user what went wrong.
This commit is contained in:
Sarah Hoffmann
2021-01-30 16:20:10 +01:00
parent 45ea73913f
commit e629a175ed
11 changed files with 45 additions and 20 deletions

View File

@@ -13,6 +13,7 @@ import nominatim.cli
import nominatim.indexer.indexer
import nominatim.tools.refresh
import nominatim.tools.replication
from nominatim.errors import UsageError
def call_nominatim(*args):
return nominatim.cli.nominatim(module_dir='build/module',
@@ -150,16 +151,14 @@ def test_replication_command(monkeypatch, temp_db, params, func):
def test_replication_update_bad_interval(monkeypatch, temp_db):
monkeypatch.setenv('NOMINATIM_REPLICATION_UPDATE_INTERVAL', 'xx')
with pytest.raises(ValueError):
call_nominatim('replication')
assert call_nominatim('replication') == 1
def test_replication_update_bad_interval_for_geofabrik(monkeypatch, temp_db):
monkeypatch.setenv('NOMINATIM_REPLICATION_URL',
'https://download.geofabrik.de/europe/ireland-and-northern-ireland-updates')
with pytest.raises(RuntimeError, match='Invalid replication.*'):
call_nominatim('replication')
assert call_nominatim('replication') == 1
@pytest.mark.parametrize("state, retval", [