[Zope-CVS] CVS: Products/CompositePage - slot.py:1.14

Shane Hathaway shane at zope.com
Tue Jan 6 11:38:29 EST 2004


Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv12119

Modified Files:
	slot.py 
Log Message:
Changed the error handling to make use of the site error_log.

Also, since the site error log already generates random identifiers
for matching up exceptions, slot.py no longer needs to generate
random numbers of its own.



=== Products/CompositePage/slot.py 1.13 => 1.14 ===
--- Products/CompositePage/slot.py:1.13	Mon Dec 29 11:59:21 2003
+++ Products/CompositePage/slot.py	Tue Jan  6 11:38:28 2004
@@ -19,10 +19,9 @@
 import os
 import sys
 from cgi import escape
-import random
 
 import Globals
-from Acquisition import aq_base, aq_inner, aq_parent
+from Acquisition import aq_base, aq_inner, aq_parent, aq_acquire
 from ZODB.POSException import ConflictError
 from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
@@ -53,12 +52,18 @@
 <div class="slot_element_body">%s</div>
 </div>'''
 
-# VIEW_TAG includes a <div> just to ensure that the element is
+# view_tag includes a <div> just to ensure that the element is
 # rendered as an HTML block in both editing mode and view mode.
 view_tag = '''<div>
 %s
 </div>'''
 
+# error_tag lets the user click on the 'log' link even if the
+# container normally stops clicks.
+error_tag = '''%s
+(<a href="%s" onmousedown="document.location=this.href">log</a>)'''
+
+
 class NullElement(SimpleItem):
     """Temporary slot content
     """
@@ -158,23 +163,7 @@
                 # Ugly ZODB requirement: don't catch ConflictErrors
                 raise
             except:
-                # Use a random identifier to make it possible to
-                # match the display with the log.
-                ref = random.randrange(10000, 100000)
-                if editing:
-                    # Show editors the real error
-                    t, v = sys.exc_info()[:2]
-                    t = getattr(t, '__name__', t)
-                    msg = "An error occurred. %s" % (
-                        escape(('%s: %s' % (t, v))[:80]))
-                else:
-                    # Show viewers a simplified error with a number
-                    msg = ("An error occurred while generating "
-                            "this part of the page.")
-                text = "%s (#%d)" % (msg, ref)
-                LOG("Composite", ERROR,
-                    "Error in a page element (#%d)" % ref,
-                    error=sys.exc_info())
+                text = self._handleError(editing)
 
             if editing:
                 base = aq_base(obj)
@@ -202,6 +191,32 @@
             res.append(target_tag % (myid, index, mypath, index))
 
         return res
+
+
+    def _handleError(self, editing):
+        exc_info = sys.exc_info()
+        try:
+            if editing:
+                # Show editors the real error
+                t, v = exc_info[:2]
+                t = getattr(t, '__name__', t)
+                msg = "An error occurred. %s" % (
+                    escape(('%s: %s' % (t, v))[:80]))
+            else:
+                # Show viewers a simplified error with a number
+                msg = ("An error occurred while generating "
+                        "this part of the page.")
+            try:
+                log = aq_acquire(self, '__error_log__', containment=1)
+            except AttributeError:
+                LOG("Composite", ERROR, "Error in a page element",
+                    error=exc_info)
+                return msg
+            else:
+                error_log_url = log.raising(exc_info)
+                return error_tag % (msg, error_log_url)
+        finally:
+            del exc_info
 
 Globals.InitializeClass(Slot)
 




More information about the Zope-CVS mailing list