mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 19:07:58 +00:00
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:
@@ -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", [
|
||||
|
||||
@@ -7,6 +7,7 @@ import tempfile
|
||||
import pytest
|
||||
|
||||
from nominatim.config import Configuration
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
DEFCFG_DIR = Path(__file__) / '..' / '..' / '..' / 'settings'
|
||||
|
||||
@@ -123,7 +124,7 @@ def test_get_int_bad_values(monkeypatch, value):
|
||||
|
||||
monkeypatch.setenv('NOMINATIM_FOOBAR', value)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(UsageError):
|
||||
config.get_int('FOOBAR')
|
||||
|
||||
|
||||
@@ -132,7 +133,7 @@ def test_get_int_empty():
|
||||
|
||||
assert config.DATABASE_MODULE_PATH == ''
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(UsageError):
|
||||
config.get_int('DATABASE_MODULE_PATH')
|
||||
|
||||
|
||||
|
||||
@@ -28,5 +28,5 @@ def test_cursor_scalar(db, temp_db_cursor):
|
||||
|
||||
def test_cursor_scalar_many_rows(db):
|
||||
with db.cursor() as cur:
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(RuntimeError):
|
||||
cur.scalar('SELECT * FROM pg_tables')
|
||||
|
||||
@@ -6,9 +6,10 @@ import datetime as dt
|
||||
import pytest
|
||||
|
||||
import nominatim.db.status
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
def test_compute_database_date_place_empty(status_table, place_table, temp_db_conn):
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(UsageError):
|
||||
nominatim.db.status.compute_database_date(temp_db_conn)
|
||||
|
||||
OSM_NODE_DATA = """\
|
||||
@@ -44,7 +45,7 @@ def test_compute_database_broken_api(monkeypatch, status_table, place_row, temp_
|
||||
|
||||
monkeypatch.setattr(nominatim.db.status, "get_url", mock_url)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(UsageError):
|
||||
date = nominatim.db.status.compute_database_date(temp_db_conn)
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from osmium.replication.server import OsmosisState
|
||||
|
||||
import nominatim.tools.replication
|
||||
import nominatim.db.status as status
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
OSM_NODE_DATA = """\
|
||||
<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
|
||||
@@ -24,7 +25,7 @@ def test_init_replication_bad_base_url(monkeypatch, status_table, place_row, tem
|
||||
|
||||
monkeypatch.setattr(nominatim.db.status, "get_url", lambda u : OSM_NODE_DATA)
|
||||
|
||||
with pytest.raises(RuntimeError, match="Failed to reach replication service"):
|
||||
with pytest.raises(UsageError, match="Failed to reach replication service"):
|
||||
nominatim.tools.replication.init_replication(temp_db_conn, 'https://test.io')
|
||||
|
||||
|
||||
@@ -90,7 +91,7 @@ def update_options(tmpdir):
|
||||
max_diff_size=1)
|
||||
|
||||
def test_update_empty_status_table(status_table, temp_db_conn):
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(UsageError):
|
||||
nominatim.tools.replication.update(temp_db_conn, {})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user