mirror of
https://github.com/searx/searx
synced 2025-02-23 07:07:42 +01:00
Provide better error message if settings.yml cannot be loaded
Closes #3184
This commit is contained in:
parent
f231d79a5d
commit
03eb9c2461
@ -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']
|
||||
|
@ -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()
|
||||
if user_settings_path is None or not load_user_setttings:
|
||||
|
||||
# no user settings
|
||||
if user_settings_path is None or not load_user_setttings:
|
||||
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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user