mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 15:00:01 +00:00
Exception handling: include a random string to identify stacks from log
This commit is contained in:
parent
36d3f8aed0
commit
6b49af4fb7
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import string
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from flask_assets import Bundle # noqa F401
|
from flask_assets import Bundle # noqa F401
|
||||||
|
@ -7,6 +8,7 @@ from flask_assets import Bundle # noqa F401
|
||||||
from nyaa.api_handler import api_blueprint
|
from nyaa.api_handler import api_blueprint
|
||||||
from nyaa.extensions import assets, db, fix_paginate, toolbar
|
from nyaa.extensions import assets, db, fix_paginate, toolbar
|
||||||
from nyaa.template_utils import bp as template_utils_bp
|
from nyaa.template_utils import bp as template_utils_bp
|
||||||
|
from nyaa.utils import random_string
|
||||||
from nyaa.views import register_views
|
from nyaa.views import register_views
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,9 +48,16 @@ def create_app(config):
|
||||||
if not app.config['DEBUG']:
|
if not app.config['DEBUG']:
|
||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
def internal_error(exception):
|
def internal_error(exception):
|
||||||
app.logger.error(exception)
|
random_id = random_string(8, string.ascii_uppercase + string.digits)
|
||||||
flask.flash(flask.Markup(
|
# Pst. Not actually unique, but don't tell anyone!
|
||||||
'<strong>An error occurred!</strong> Debug information has been logged.'), 'danger')
|
app.logger.error('Exception occurred! Unique ID: %s', random_id, exc_info=exception)
|
||||||
|
markup_source = ' '.join([
|
||||||
|
'<strong>An error occurred!</strong>',
|
||||||
|
'Debug information has been logged.',
|
||||||
|
'Please pass along this ID: <kbd>{}</kbd>'.format(random_id)
|
||||||
|
])
|
||||||
|
|
||||||
|
flask.flash(flask.Markup(markup_source), 'danger')
|
||||||
return flask.redirect(flask.url_for('main.home'))
|
return flask.redirect(flask.url_for('main.home'))
|
||||||
|
|
||||||
# Get git commit hash
|
# Get git commit hash
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import functools
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import random
|
||||||
|
import string
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +24,12 @@ def sorted_pathdict(input_dict):
|
||||||
return OrderedDict(sorted(directories.items()) + sorted(files.items()))
|
return OrderedDict(sorted(directories.items()) + sorted(files.items()))
|
||||||
|
|
||||||
|
|
||||||
|
def random_string(length, charset=None):
|
||||||
|
if charset is None:
|
||||||
|
charset = string.ascii_letters + string.digits
|
||||||
|
return ''.join(random.choice(charset) for i in range(length))
|
||||||
|
|
||||||
|
|
||||||
def cached_function(f):
|
def cached_function(f):
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
f._cached_value = sentinel
|
f._cached_value = sentinel
|
||||||
|
|
Loading…
Reference in a new issue