on master help sign in
Merge pull request #961 from kvch/user-visible-engine-errors

show engine errors in infobox && add new error alert

commitc30f73f8fda2b51cfd95967a29cc34a2036ffddd authorAdam Tauber <asciimoo@gmail.com> dateSat 15 Jul 2017, 18:24 (9 years ago) parent3bd5ce6bdd9528
6 files changed+34−5
searx/results.py+4 searx/search.py+4 searx/templates/oscar/messages/no_results.html+12−4 searx/templates/oscar/results.html+10 searx/webapp.py+3−1 tests/unit/test_webapp.py+1
searx/results.py+4
@@ -135,6 +135,7 @@ class ResultContainer(object):
135135 self._number_of_results = []
136136 self._ordered = False
137137 self.paging = False
138+ self.unresponsive_engines = []
138139
139140 def extend(self, engine_name, results):
140141 for result in list(results):
@@ -304,3 +305,6 @@ class ResultContainer(object):
304305 if not resultnum_sum or not self._number_of_results:
305306 return 0
306307 return resultnum_sum / len(self._number_of_results)
308+
309+ def add_unresponsive_engine(self, engine_name):
310+ self.unresponsive_engines.append(engine_name)
searx/search.py+4
@@ -20,6 +20,7 @@ import sys
2020import threading
2121from time import time
2222from uuid import uuid4
23+from flask_babel import gettext
2324import requests.exceptions
2425import searx.poolrequests as requests_lib
2526from searx.engines import (
@@ -133,18 +134,21 @@ def search_one_request_safe(engine_name, query, request_params, result_container
133134 requests_exception = False
134135
135136 if (issubclass(e.__class__, requests.exceptions.Timeout)):
137+ result_container.add_unresponsive_engine((engine_name, gettext('timeout')))
136138 # requests timeout (connect or read)
137139 logger.error("engine {0} : HTTP requests timeout"
138140 "(search duration : {1} s, timeout: {2} s) : {3}"
139141 .format(engine_name, search_duration, timeout_limit, e.__class__.__name__))
140142 requests_exception = True
141143 elif (issubclass(e.__class__, requests.exceptions.RequestException)):
144+ result_container.add_unresponsive_engine((engine_name, gettext('request exception')))
142145 # other requests exception
143146 logger.exception("engine {0} : requests exception"
144147 "(search duration : {1} s, timeout: {2} s) : {3}"
145148 .format(engine_name, search_duration, timeout_limit, e))
146149 requests_exception = True
147150 else:
151+ result_container.add_unresponsive_engine((engine_name, gettext('unexpected crash')))
148152 # others errors
149153 logger.exception('engine {0} : exception : {1}'.format(engine_name, e))
150154
searx/templates/oscar/messages/no_results.html+12−4
@@ -1,9 +1,17 @@
11{% from 'oscar/macros.html' import icon %}
2+{% if unresponsive_engines %}
3+<div class="alert alert-danger fade in" role="alert">
4+ <p><strong class="lead">{{ icon('remove-sign') }} {{ _('Error!') }}</strong> {{ _('Engines cannot retrieve results.') }}</p>
5+ <p>
6+ {% for engine_name, error_type in unresponsive_engines %}
7+ {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}
8+ {% endfor %}
9+ </p>
10+ <p><small>{{ _('Please, try again later or find another searx instance.') }}</small></p>
11+</div>
12+{% else %}
213<div class="alert alert-info fade in" role="alert">
3− <button class="close" data-dismiss="alert" type="button">
4− <span aria-hidden="true">×</span>
5− <span class="sr-only">{{ _('Close') }}</span>
6− </button>
714 <strong class="lead">{{ icon('info-sign') }} {{ _('Sorry!') }}</strong>
815 {{ _('we didn\'t find any results. Please use another query or search in more categories.') }}
916</div>
17+{% endif %}
searx/templates/oscar/results.html+10
@@ -94,6 +94,16 @@
9494 {% if number_of_results != '0' %}
9595 <p><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
9696 {% endif %}
97+
98+ {% if unresponsive_engines and results|length >= 1 %}
99+ <div class="alert alert-danger fade in" role="alert">
100+ <p>{{ _('Engines cannot retrieve results') }}:</p>
101+ {% for engine_name, error_type in unresponsive_engines %}
102+ {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}
103+ {% endfor %}
104+ </div>
105+ {% endif %}
106+
97107 {% if infoboxes %}
98108 {% for infobox in infoboxes %}
99109 {% include 'oscar/infobox.html' %}
searx/webapp.py+3−1
@@ -534,7 +534,8 @@ def index():
534534 'answers': list(result_container.answers),
535535 'corrections': list(result_container.corrections),
536536 'infoboxes': result_container.infoboxes,
537− 'suggestions': list(result_container.suggestions)}),
537+ 'suggestions': list(result_container.suggestions),
538+ 'unresponsive_engines': list(result_container.unresponsive_engines)}),
538539 mimetype='application/json')
539540 elif output_format == 'csv':
540541 csv = UnicodeWriter(StringIO())
@@ -573,6 +574,7 @@ def index():
573574 corrections=result_container.corrections,
574575 infoboxes=result_container.infoboxes,
575576 paging=result_container.paging,
577+ unresponsive_engines=result_container.unresponsive_engines,
576578 current_language=search_query.lang,
577579 base_url=get_base_url(),
578580 theme=get_current_theme_name(),
tests/unit/test_webapp.py+1
@@ -39,6 +39,7 @@ class ViewsTestCase(SearxTestCase):
3939 corrections=set(),
4040 suggestions=set(),
4141 infoboxes=[],
42+ unresponsive_engines=[],
4243 results=self.test_results,
4344 results_number=lambda: 3,
4445 results_length=lambda: len(self.test_results))