helmgast / lore

A web-based storytelling framework.
4 stars 0 forks source link

Bug if starting with no db config #258

Open ripperdoc opened 4 years ago

ripperdoc commented 4 years ago

Multiple exceptions coming due to lack of password, can be handled more nicely:

[2020-10-02 21:13:52 +0000] [7] [ERROR] Error handling request /meta/articles/?debug
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/mongoengine/connection.py", line 318, in _create_connection
    return connection_class(**connection_settings)
  File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 691, in __init__
    self.__options = options = ClientOptions(
  File "/usr/local/lib/python3.8/site-packages/pymongo/client_options.py", line 152, in __init__
    self.__credentials = _parse_credentials(
  File "/usr/local/lib/python3.8/site-packages/pymongo/client_options.py", line 38, in _parse_credentials
    return _build_credentials_tuple(
  File "/usr/local/lib/python3.8/site-packages/pymongo/auth.py", line 157, in _build_credentials_tuple
    raise ConfigurationError("A password is required.")
pymongo.errors.ConfigurationError: A password is required.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1610, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1831, in preprocess_request
    rv = func()
  File "/usr/local/lib/python3.8/site-packages/flask_debugtoolbar/__init__.py", line 151, in process_request
    DebugToolbar(real_request, self.jinja_env))
  File "/usr/local/lib/python3.8/site-packages/flask_debugtoolbar/toolbar.py", line 23, in __init__
    self.create_panels()
  File "/usr/local/lib/python3.8/site-packages/flask_debugtoolbar/toolbar.py", line 33, in create_panels
    panel_instance = panel_class(jinja_env=self.jinja_env,
  File "/usr/src/app/tools/mongoengine_debug_toolbar.py", line 15, in __init__
    self.query_counter = query_counter()
  File "/usr/local/lib/python3.8/site-packages/mongoengine/context_managers.py", line 189, in __init__
    self.db = get_db(alias=alias)
  File "/usr/local/lib/python3.8/site-packages/mongoengine/connection.py", line 356, in get_db
    conn = get_connection(alias)
  File "/usr/local/lib/python3.8/site-packages/mongoengine/connection.py", line 305, in get_connection
    connection = _create_connection(
  File "/usr/local/lib/python3.8/site-packages/mongoengine/connection.py", line 320, in _create_connection
    raise ConnectionFailure("Cannot connect to database {} :\n{}".format(alias, e))
mongoengine.connection.ConnectionFailure: Cannot connect to database default :
A password is required.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 134, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/src/app/lore/extensions.py", line 87, in __call__
    return self.app(environ, start_response)
  File "/usr/local/lib/python3.8/site-packages/werkzeug/middleware/proxy_fix.py", line 232, in __call__
    return self.app(environ, start_response)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1518, in handle_user_exception
    return handler(e)
  File "/usr/src/app/lore/app.py", line 420, in db_error
    return render_template("error/nodb.html", root_template="_root.html"), 500
  File "/usr/local/lib/python3.8/site-packages/flask/templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/usr/local/lib/python3.8/site-packages/flask/templating.py", line 116, in _render
    rv = template.render(context)
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "/usr/src/app/lore/templates/error/nodb.html", line 1, in top-level template code
    {% extends root_template %}
  File "/usr/src/app/lore/templates/_root.html", line 111, in top-level template code
    {% block navbar %}
  File "/usr/src/app/lore/templates/_root.html", line 131, in block "navbar"
    {% block navbar_left %}
  File "/usr/src/app/lore/templates/_root.html", line 132, in block "navbar_left"
    {% call(privileged) MACRO.AUTHORIZED(access_policy['publisher'].authorize('list', res=user)) %}
  File "/usr/src/app/lore/api/resource.py", line 1392, in authorize
    user = g.user
  File "/usr/local/lib/python3.8/site-packages/werkzeug/local.py", line 348, in __getattr__
    return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'user'