Provide better error message if settings.yml cannot be loaded

Closes #3184
This commit is contained in:
Noémi Ványi 2022-03-17 20:34:50 +01:00
parent f231d79a5d
commit 03eb9c2461
2 changed files with 20 additions and 2 deletions

View File

@ -19,12 +19,22 @@ import logging
import searx.settings_loader
from os import environ
from os.path import realpath, dirname, join, abspath, isfile
from sys import exit
from searx.exceptions import SearxSettingsException
searx_dir = abspath(dirname(__file__))
engine_dir = dirname(realpath(__file__))
static_path = abspath(join(dirname(__file__), 'static'))
settings, settings_load_message = searx.settings_loader.load_settings()
settings, settings_outgoing = {}, ''
try:
settings, settings_load_message = searx.settings_loader.load_settings()
except SearxSettingsException as e:
logger = logging.getLogger('searx')
logger.error('Failed to load settings file: {}'.format(str(e)))
exit(1)
if settings['ui']['static_path']:
static_path = settings['ui']['static_path']

View File

@ -112,8 +112,16 @@ def is_use_default_settings(user_settings):
def load_settings(load_user_setttings=True):
default_settings_path = get_default_settings_path()
user_settings_path = get_user_settings_path()
# no user settings
if user_settings_path is None or not load_user_setttings:
# no user settings
if default_settings_path is None:
raise SearxSettingsException(
'missing default settings.yml file and there is no user configured file.\n'
'Please create a configuration file and put it under the root of searx or in /etc/searx or'
'configure the path in SEARX_SETTINGS_PATH.',
None,
)
return (load_yaml(default_settings_path),
'load the default settings from {}'.format(default_settings_path))