diff options
author | Alexandre Flament <alex@al-f.net> | 2021-08-14 18:03:31 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-08-14 18:03:31 +0200 |
commit | 3f3b5d6181e0bc07a5177651d3221a479b214523 (patch) | |
tree | e34db5f1ce8d3be4de59eebf3a15a5898a8ed5fe /searx/plugins | |
parent | 7f18cbbee0e0eccc86b78455d4aec38e391318ec (diff) | |
download | searxng-3f3b5d6181e0bc07a5177651d3221a479b214523.tar.gz searxng-3f3b5d6181e0bc07a5177651d3221a479b214523.zip |
[mod] plugins: minor change
required attributes: display a different message
when the attribute has the wrong type
Diffstat (limited to 'searx/plugins')
-rw-r--r-- | searx/plugins/__init__.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 45b210662..3a35f7025 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -40,7 +40,8 @@ required_attrs = (('name', str), ('default_on', bool)) optional_attrs = (('js_dependencies', tuple), - ('css_dependencies', tuple)) + ('css_dependencies', tuple), + ('preference_section', str)) class Plugin(): @@ -63,9 +64,17 @@ class PluginStore(): plugins = load_external_plugins(plugins) for plugin in plugins: for plugin_attr, plugin_attr_type in required_attrs: - if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type): + if not hasattr(plugin, plugin_attr): logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin)) exit(3) + attr = getattr(plugin, plugin_attr) + if not isinstance(attr, plugin_attr_type): + type_attr = str(type(attr)) + logger.critical( + 'attribute "{0}" is of type {2}, must be of type {3}, cannot load plugin: {1}' + .format(plugin_attr, plugin, type_attr, plugin_attr_type) + ) + exit(3) for plugin_attr, plugin_attr_type in optional_attrs: if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type): setattr(plugin, plugin_attr, plugin_attr_type()) |