← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~hyask/autopkgtest-cloud:skia/better_handle_exceptions into autopkgtest-cloud:master

 

Skia has proposed merging ~hyask/autopkgtest-cloud:skia/better_handle_exceptions into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/469226

This avoids eating the traceback when an exception is thrown, so that we can actually debug the issue.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/better_handle_exceptions into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index a4af4d8..93c8715 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -6,6 +6,7 @@ import json
 import os
 import re
 import sqlite3
+import traceback
 from collections import OrderedDict
 from wsgiref.handlers import CGIHandler
 
@@ -964,11 +965,6 @@ def statistics():
     )
 
 
-def invalid(inv_exception, code=400):
-    """Return message and HTTP error code for an invalid request"""
-    return render("browse-error.html", error=inv_exception, code=code)
-
-
 if __name__ == "__main__":
 
     @app.errorhandler(Exception)
@@ -976,13 +972,17 @@ if __name__ == "__main__":
         # If the exception doesn't have the exit_code method, it's not an expected
         # exception defined in helpers/exceptions.py
         try:
-            return invalid(error, error.exit_code())
-        except Exception as e:
-            return render(
-                "browse-error.html",
-                error=f"Error {e} during handling of {error}",
-                code=500,
-            )
+            exit_code = error.exit_code()
+        except Exception:
+            exit_code = 500
+
+        traceback.print_exception(error)
+        return render(
+            "browse-error.html",
+            error=error,
+            tb=traceback.format_exception(error),
+            exit_code=exit_code,
+        )
 
     app.config["DEBUG"] = True
     init_config()
diff --git a/charms/focal/autopkgtest-web/webcontrol/static/style.css b/charms/focal/autopkgtest-web/webcontrol/static/style.css
index 4217121..086d6a6 100644
--- a/charms/focal/autopkgtest-web/webcontrol/static/style.css
+++ b/charms/focal/autopkgtest-web/webcontrol/static/style.css
@@ -151,3 +151,10 @@ th.sticky-table-headers {
 .unfinished {
   color: grey;
 }
+
+.code {
+  font-family: monospace;
+  color: #eeeeee;
+  background: #111111;
+  border-color: #666666;
+}
diff --git a/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html b/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
index ab2f9fc..0edf974 100644
--- a/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
+++ b/charms/focal/autopkgtest-web/webcontrol/templates/browse-error.html
@@ -1,7 +1,7 @@
 {% extends "browse-layout.html" %}
 {% block content %}
   <div style="background: #f33; padding: 0.5em 1.5em;">
-    <h1>Error:</h1>
+    <h1>Error {{ exit_code }}:</h1>
     <p>{{ error }}</p>
   </div>
   <p>
@@ -9,4 +9,8 @@
     can contact them via the ubuntu-quality mailing list, or via the #ubuntu-quality
     IRC channel on irc.libera.chat (highlight 'qa-help' for more reactivity).
   </p>
+  <p>Please include the details below:</p>
+  <pre class="code">
+  {% for line in tb -%}{{ line }}{%- endfor -%}
+  </pre>
 {% endblock content %}