moar pimping of the error page... at this point, error messages are becoming more of a feature than a bug
authorTero Marttila <terom@fixme.fi>
Mon, 16 Feb 2009 03:25:00 +0200
changeset 137 a25d1bf758e6
parent 136 c69a176b3620
child 138 7dbe0ee1a27b
moar pimping of the error page... at this point, error messages are becoming more of a feature than a bug
error.py
--- a/error.py	Mon Feb 16 02:55:17 2009 +0200
+++ b/error.py	Mon Feb 16 03:25:00 2009 +0200
@@ -15,6 +15,9 @@
     else :
         return msg
 
+def build_link (title, url) :
+    return '<a href="%s">%s</a>' % (cgi.escape(url, True), cgi.escape(title))
+
 def build_error (exc_info=None, env=None) :
     """
         Dumps out a raw traceback of the given/current exception to stdout.
@@ -44,22 +47,31 @@
 
     # working copy path?
     try :
-        from config import HG_WC_PATH
+        from config import HG_WC_PATH, HGWEB_URL
 
         wc_path = HG_WC_PATH
+        hgweb_url = HGWEB_URL
 
     except :
         # a good guess
         wc_path = '.'
+        hgweb_url = None
     
     # version?
     try :
-        from version import version_string
+        from version import version_string, version_link_hg
 
         version = version_string(wc_path)
+
+        if hgweb_url :
+            version_href = version_link_hg(wc_path, hgweb_url)
+
+        else :
+            version_href = None
     
     except :
         version = None
+        version_href = None
     
     # the exception type
     exception_str = traceback.format_exception_only(*exc_info[:2])[-1]
@@ -71,19 +83,31 @@
     trac_url = "http://projects.qmsk.net/irclogs2/trac"
     
     # ticket list
-    query_url = "%s/query" % trac_url
+    trac_query = build_link("All tickets", "%s/query" % trac_url)
 
     # submit ticket
     submit_args = dict(type='defect')
-
+    
+    # handle optional components
     if url :
         submit_args['url'] = url
-
+        trac_query_url = build_link("Same URL", "%s/query?url=%s" % (trac_url, urllib.quote(url)))
+    else :
+        trac_query_url = ""
+    
     if version :
         submit_args['revision'] = version
+        trac_query_version = build_link("Same version", "%s/query?revision=%s" % (trac_url, urllib.quote(version)))
+
+    else :
+        trac_query_version = ""
     
     if exception_str :
         submit_args['summary'] = truncate(exception_str, 140)
+        trac_query_err = build_link("Same error", "%s/query?summary=%s" % (trac_url, urllib.quote(exception_str.rstrip())))
+
+    else :
+        trac_query_err = ""
 
     if traceback_lines :
         # this is big
@@ -104,20 +128,55 @@
 <html><head><title>500 Internal Server Error</title></head><body>
 <h1>Oops!</h1>
 <p>
-    An error occured, which was not logged, and will not be reported to anybody. It might be your fault, or it might be
-    mine. 
+    An error occured, which was not logged, and was not reported to anybody. It might be your fault, or it might be mine.
 </p>
+
 <p>
-    You can try poking the administrator of this site to see if they respond, or submit a defect ticket at the <a href="%(query_url)s">Project Trac</a>, using the following link:
+    You can try:
+    <ol style="list-style-type: lower-alpha">
+        <li><strong>Poking</strong> the administrator of this site to see if they respond</li>
+        <li><strong>Looking</strong> for similar issue tickets with:
+          <ul>
+            <li>%(trac_query)s</li>
+            <li>%(trac_query_url)s</li>
+            <li>%(trac_query_version)s</li>
+            <li>%(trac_query_err)s</li>
+          </ul>
+        </li>
+        <li><strong>Submitting</strong> a new ticket using the following link (quick &amp; easy):</li>
+    </ol>
 </p>
 <pre>
     <a href="%(submit_url)s">%(submit_url_short)s</a>
 </pre>
+
 <h2>Details:</h2>
+<p>The page you tried to request was:</p>
+<pre>
+    %(url)s
+</pre>
+
+<p>The software version is:</p>
+<pre>
+    %(version_link)s
+</pre>
+
+<p>The error was:</p>
+<pre>
+    %(exception)s
+</pre>
+
+<p>The traceback was:</p>
 <pre>%(traceback)s</pre>
 </body></html>""" % dict(
-        traceback           = cgi.escape(''.join(traceback_lines)),
-        query_url           = query_url,
+        url                 = url if url else 'Unknown',
+        version_link        = version_href if version_href else 'Unknown',
+        exception           = truncate(exception_str, 512),
+        traceback           = cgi.escape(''.join('   ' + line for line in traceback_lines)),
+        trac_query          = trac_query,
+        trac_query_url      = trac_query_url,
+        trac_query_version  = trac_query_version,
+        trac_query_err      = trac_query_err,
         submit_url          = submit_url,
         submit_url_short    = truncate(submit_url, 120)
     )).encode('utf-8'))