Merge ~hyask/autopkgtest-cloud:skia/browse_exception_handler into autopkgtest-cloud:master

Proposed by Skia
Status: Merged
Merged at revision: ca8775ec7a7dcebd94bcb6cdc8edf51d4f42c1cd
Proposed branch: ~hyask/autopkgtest-cloud:skia/browse_exception_handler
Merge into: autopkgtest-cloud:master
Diff against target: 96 lines (+38/-7)
3 files modified
charms/focal/autopkgtest-web/webcontrol/browse.cgi (+24/-5)
charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py (+5/-0)
charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html (+9/-2)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+461059@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Andersson (andersson123) wrote :

LGTM! But failed CI, fix that and I'll approve :)

Revision history for this message
Tim Andersson (andersson123) wrote :

Sorry, just realised I do have a qualm with this:

Please amend the commit message to accurately reflect the changes. This commit doesn't just add a generic exception handler ;)

Revision history for this message
Tim Andersson (andersson123) :
review: Needs Fixing
Revision history for this message
Skia (hyask) wrote :

Rebased and split into two different proper commits.

Revision history for this message
Tim Andersson (andersson123) wrote :

The first commit message doesn't mention the new HTML at all, and it's not clear the exception handler is user facing in this instance.

The second commit message needs a bit of work too IMO, "properly" isn't a good word to use as it's undefined. A bit more detail please.

Revision history for this message
Skia (hyask) wrote :

I'm not sure if spending that much time on commit messages was really worth it, but here you go :-)

Revision history for this message
Tim Andersson (andersson123) wrote :

Of course it was worth it. We need good, detailed & descriptive high quality commit messages for our git archaeology. We are the QA team after all.

Anyway. LGTM now.

review: Approve
Revision history for this message
Tim Andersson (andersson123) wrote :

I also just want to add that I'm not being nitpicky or pedantic with wanting more detailed commit messages. It's a standard I've been held to in my MP's so I'm just passing it on.

Revision history for this message
Skia (hyask) wrote :

Sure, np :-)

That reminds me that Brian wanted to find a warcry for the QA team. That would have been appropriate in that situation XD

QA MF!

Revision history for this message
Brian Murray (brian-murray) wrote :

I think I was really looking for a team haka.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
2index 2918276..f71b406 100755
3--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
4+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
5@@ -12,6 +12,7 @@ from wsgiref.handlers import CGIHandler
6
7 import flask
8 from helpers.admin import select_abnormally_long_jobs
9+from helpers.exceptions import RunningJSONNotFound
10 from helpers.utils import get_all_releases, get_supported_releases
11 from werkzeug.middleware.proxy_fix import ProxyFix
12
13@@ -62,10 +63,9 @@ def get_running_jobs():
14 try:
15 with open(RUNNING_CACHE) as f:
16 # package -> runhash -> release -> arch -> (params, duration, logtail)
17- running_info = json.load(f)
18- except FileNotFoundError:
19- running_info = {}
20- return running_info
21+ return json.load(f)
22+ except FileNotFoundError as e:
23+ raise RunningJSONNotFound(e) from e
24
25
26 def render(template, code=200, **kwargs):
27@@ -90,7 +90,7 @@ def render(template, code=200, **kwargs):
28 template,
29 base_url=flask.url_for("index_root"),
30 static_url=flask.url_for("static", filename=""),
31- **kwargs
32+ **kwargs,
33 ),
34 code,
35 )
36@@ -531,6 +531,25 @@ def statistics():
37 )
38
39
40+def invalid(inv_exception, code=400):
41+ """Return message and HTTP error code for an invalid request"""
42+ return render("browse-error.html", error=inv_exception, code=code)
43+
44+
45+@app.errorhandler(Exception)
46+def all_exception_handler(error):
47+ # If the exception doesn't have the exit_code method, it's not an expected
48+ # exception defined in helpers/exceptions.py
49+ try:
50+ return invalid(error, error.exit_code())
51+ except Exception as e:
52+ return render(
53+ "browse-error.html",
54+ error=f"Error {e} during handling of {error}",
55+ code=500,
56+ )
57+
58+
59 if __name__ == "__main__":
60 app.config["DEBUG"] = True
61 init_config()
62diff --git a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
63index becb8c7..e94164e 100644
64--- a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
65+++ b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
66@@ -10,6 +10,11 @@ EXAMPLE_URL = (
67 )
68
69
70+class RunningJSONNotFound(FileNotFoundError):
71+ def exit_code(self):
72+ return 500
73+
74+
75 class WebControlException(Exception):
76 def __init__(self, message, exit_code):
77 super().__init__(message)
78diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
79index af23654..12b6cf7 100644
80--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
81+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
82@@ -1,5 +1,12 @@
83 {% extends "browse-layout.html" %}
84 {% block content %}
85-<h1>Error:</h1>
86-<p>{{error}}</p>
87+<div style="background: #f33; padding: 0.5em 1.5em;">
88+ <h1>Error:</h1>
89+ <p>{{ error }}</p>
90+</div>
91+<p>
92+A server error has occured, please contact a member of the Ubuntu QA team. You
93+can contact them via the ubuntu-quality mailing list, or via the #ubuntu-quality
94+IRC channel on irc.libera.chat (highlight 'qa-help' for more reactivity).
95+</p>
96 {% endblock %}

Subscribers

People subscribed via source and target branches