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

Shane Hathaway shane at zope.com
Tue Oct 14 18:40:05 EDT 2003


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

Modified Files:
	slot.py 
Log Message:
When an error occurs, log it and show a clean message and an identifier.

End users will no longer see exception details (since that can be confusing),
but they will see a number that they can give to site administrators.
Site admins can then match the number with a log entry.



=== Products/CompositePage/slot.py 1.4 => 1.5 ===
--- Products/CompositePage/slot.py:1.4	Wed Oct  8 10:51:12 2003
+++ Products/CompositePage/slot.py	Tue Oct 14 18:40:04 2003
@@ -19,6 +19,7 @@
 import os
 import sys
 from cgi import escape
+import random
 
 import Globals
 from Acquisition import aq_base, aq_inner, aq_parent
@@ -27,6 +28,7 @@
 from DocumentTemplate.DT_Util import safe_callable
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from AccessControl import ClassSecurityInfo
+from zLOG import LOG, ERROR
 
 try:
     # Use OrderedFolder if it's available.
@@ -139,10 +141,23 @@
                 # Ugly ZODB requirement: don't catch ConflictErrors
                 raise
             except:
-                t, v = sys.exc_info()[:2]
-                t = getattr(t, '__name__', t)
-                text = "<code>%s</code>" % (
-                    escape(('%s: %s' % (t, v))[:80]))
+                # 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 
+                    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())
 
             if editing:
                 path = escape('/'.join(obj.getPhysicalPath()))




More information about the Zope-CVS mailing list