1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# 404 error in logs
We get many 404's in GN logs. Can we rewire that so no log entries appear as a full stack dump?
## Tags
* type: enhancement
* keywords: deployment, 404
* assigned: bonfacem, pjotrp
* status: unclear
* priority: low
## Notes
=> https://flask.palletsprojects.com/en/2.0.x/errorhandling/
Some of those 404's in our log
mean that we forgot to package something; for
example:
=>
https://git.genenetwork.org/guix-bioinformatics/guix-bioinformatics/commit/e80fe4ddcf15e21004b8135cf8af34b458697f64
Removing the 404's would prevent us from catching important errors if
ever they occur. I suggest we fix the 404's; some of them have a
cascading effect, like the font-awesome missing "webfonts" folder I
just fixed that leads to a lot of unnecessary 404s.
For error handling, I think that will evolve with the code-base with
time as it gets leaner. One way the aforementioned flask page
recommends handling errors is by creating custom errors for your
particular subject-domain needs and probably send a 5xx message that's
more helpful. At the moment we are using one error-handler for
everything(notice the generic "Exception")! See:
```
@app.errorhandler(Exception)
def handle_bad_request(e):
err_msg = str(e)
logger.error(err_msg)
logger.error(request.url)
# get the stack trace and send it to the logger
exc_type, exc_value, exc_traceback = sys.exc_info()
logger.error(traceback.format_exc())
now = datetime.datetime.utcnow()
time_str = now.strftime('%l:%M%p UTC %b %d, %Y')
formatted_lines = [request.url
+ " (" + time_str + ")"] + traceback.format_exc().splitlines()
# Handle random animations
# Use a cookie to have one animation on refresh
animation = request.cookies.get(err_msg[:32])
if not animation:
list = [fn for fn in os.listdir(
"./wqflask/static/gif/error") if fn.endswith(".gif")]
animation = random.choice(list)
resp = make_response(render_template("error.html", message=err_msg,
stack=formatted_lines, error_image=animation, version=GN_VERSION))
# logger.error("Set cookie %s with %s" % (err_msg, animation))
resp.set_cookie(err_msg[:32], animation)
return resp
```
I'll look a way for removing this:
```
exc_type, exc_value, exc_traceback = sys.exc_info()
logger.error(traceback.format_exc())
```
with a more sane, but probably still useful,
log. That's where I problem IIUC lies.
|