Skip to content

Commit 8f5b8e4

Browse files
author
Richard Jones
committed
much nicer error messages when there's a templating error
1 parent b1bc7f9 commit 8f5b8e4

File tree

6 files changed

+76
-35
lines changed

6 files changed

+76
-35
lines changed

TODO.txt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,36 @@ pending web: search "refinement"
4747
query values
4848
pending web: have roundup.cgi pick up instance config from the environment
4949
pending web: UNIX init.d script for roundup-server
50-
pending web: modify cgitb to handle PageTemplate errors better (see how
51-
Zope handles __traceback_supplement__ and __traceback_info__)
5250
pending web: rewritten documentation (can come after the beta though so stuff
5351
is settled) ... including relevant file names in customisation doc
5452

5553
bug: request.url is incorrect in cgi-bin environments
5654

5755

58-
done web: Re-enable link backrefs from messages (feature request #568714) (RJ)
59-
done web: have the page layout (header/footer) be templatable (RJ)
60-
done web: fixing the templating so it works (RJ)
56+
done web: Re-enable link backrefs from messages (feature request #568714)
57+
done web: have the page layout (header/footer) be templatable
58+
done web: fixing the templating so it works
6159
done web: re-work cgi interface to abstract out the explicit "issue"
62-
interface (RJ)
60+
interface
6361
done web: have index page handle mid-page errors better so header and
64-
footer are still visible (RJ)
62+
footer are still visible
6563
done hyperdb: write a backend for gadfly (it's as done as it's going to get)
66-
done hyperdb: full-text search also search certain String properties (RJ)
64+
done hyperdb: full-text search also search certain String properties
6765
done hyperdb: further split the *dbm backends from the core code, allowing
68-
easier non-dict-like backends (eg metakit, RDB) (RJ)
69-
done hyperdb: fix the journal bloat (RJ)
66+
easier non-dict-like backends (eg metakit, RDB)
67+
done hyperdb: fix the journal bloat
7068
done hyperdb: add Boolean and Number types (GM)
71-
done hyperdb: update design document (RJ)
72-
done hyperdb: entire database export and import (incl files) (RJ)
73-
done mailgw: better help message (feature request #558562) (RJ)
74-
done security: add info from doc/security.txt to design doc (RJ)
75-
done security: switch to sessions for web authentication (RJ)
69+
done hyperdb: update design document
70+
done hyperdb: entire database export and import (incl files)
71+
done mailgw: better help message (feature request #558562)
72+
done security: add info from doc/security.txt to design doc
73+
done security: switch to sessions for web authentication
7674
done security: implement and use the new logical control mechanisms
7775
done web: saving of named queries (GM, RJ)
78-
done web: handle "not found", access and item page render errors better (RJ)
79-
done web: fix double-submit by having new-item-submit redirect at end (RJ)
80-
done web: daemonify roundup-server (fork, logfile, pidfile) (RJ)
76+
done web: handle "not found", access and item page render errors better
77+
done web: fix double-submit by having new-item-submit redirect at end
78+
done web: daemonify roundup-server (fork, logfile, pidfile)
79+
done web: modify cgitb to display PageTemplate errors better
8180

8281
rejected instance: the use of non-Python configuration files (ConfigParser)
8382

roundup/cgi/PageTemplates/Expressions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
for Python expressions, string literals, and paths.
1818
"""
1919

20-
__version__='$Revision: 1.1 $'[11:-2]
20+
__version__='$Revision: 1.2 $'[11:-2]
2121

2222
import re, sys
2323
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
@@ -112,7 +112,8 @@ def _eval(self, econtext,
112112
# If the value isn't a string, assume it's a sequence
113113
# of path names.
114114
path[i:i+1] = list(val)
115-
__traceback_info__ = base = self._base
115+
base = self._base
116+
__traceback_info__ = 'sub path expression "%s"'%base
116117
if base == 'CONTEXTS':
117118
ob = econtext.contexts
118119
else:
@@ -271,8 +272,8 @@ def restrictedTraverse(self, path, securityManager,
271272
object = self
272273
#print 'TRAVERSE', (object, path)
273274
while path:
274-
__traceback_info__ = REQUEST
275275
name = path.pop()
276+
__traceback_info__ = 'looking for "%s"'%name
276277

277278
if isinstance(name, TupleType):
278279
object = apply(object, name)

roundup/cgi/PageTemplates/PythonExpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""Generic Python Expression Handler
1515
"""
1616

17-
__version__='$Revision: 1.1 $'[11:-2]
17+
__version__='$Revision: 1.2 $'[11:-2]
1818

1919
from TALES import CompilerError
2020
from string import strip, split, join, replace, lstrip
@@ -60,7 +60,7 @@ def _bind_used_names(self, econtext):
6060
return names
6161

6262
def __call__(self, econtext):
63-
__traceback_info__ = self.expr
63+
__traceback_info__ = 'python expression "%s"'%self.expr
6464
f = self._f
6565
f.func_globals.update(self._bind_used_names(econtext))
6666
return f()

roundup/cgi/cgitb.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This module was written by Ka-Ping Yee, <[email protected]>.
33
#
4-
# $Id: cgitb.py,v 1.1 2002-08-30 08:28:44 richard Exp $
4+
# $Id: cgitb.py,v 1.2 2002-09-06 07:21:31 richard Exp $
55

66
__doc__ = """
77
Extended CGI traceback handler by Ka-Ping Yee, <[email protected]>.
@@ -16,6 +16,43 @@ def breaker():
1616
'<font color="white" size="-5"> > </font> ' +
1717
'</table>' * 5)
1818

19+
def niceDict(indent, dict):
20+
l = []
21+
for k,v in dict.items():
22+
l.append('%s%s: %r'%(indent,k,v))
23+
return '\n'.join(l)
24+
25+
def pt_html(context=5):
26+
import cgi
27+
etype, evalue = sys.exc_type, sys.exc_value
28+
if type(etype) is types.ClassType:
29+
etype = etype.__name__
30+
pyver = 'Python ' + string.split(sys.version)[0] + '<br>' + sys.executable
31+
head = pydoc.html.heading(
32+
'<font size=+1><strong>%s</strong>: %s</font>'%(etype, evalue),
33+
'#ffffff', '#777777', pyver)
34+
35+
head = head + _('<p>A problem occurred in your template</p><pre>')
36+
37+
l = []
38+
for frame, file, lnum, func, lines, index in inspect.trace(context):
39+
args, varargs, varkw, locals = inspect.getargvalues(frame)
40+
if locals.has_key('__traceback_info__'):
41+
ti = locals['__traceback_info__']
42+
l.append(str(ti))
43+
if locals.has_key('__traceback_supplement__'):
44+
ts = locals['__traceback_supplement__']
45+
if len(ts) == 2:
46+
supp, context = ts
47+
l.append('in template %r'%context.id)
48+
elif len(ts) == 3:
49+
supp, context, info = ts
50+
l.append('in expression %r\n%s\n%s\n'%(info,
51+
niceDict(' ', context.global_vars),
52+
niceDict(' ', context.local_vars)))
53+
# context._scope_stack))
54+
return head + cgi.escape('\n'.join(l)) + '</pre><p>&nbsp;</p>'
55+
1956
def html(context=5):
2057
etype, evalue = sys.exc_type, sys.exc_value
2158
if type(etype) is types.ClassType:
@@ -34,7 +71,8 @@ def html(context=5):
3471
traceback = []
3572
for frame, file, lnum, func, lines, index in inspect.trace(context):
3673
if file is None:
37-
link = '&lt;file is None - probably inside <tt>eval</tt> or <tt>exec</tt>&gt;'
74+
link = '''&lt;file is None - probably inside <tt>eval</tt> or
75+
<tt>exec</tt>&gt;'''
3876
else:
3977
file = os.path.abspath(file)
4078
link = '<a href="file:%s">%s</a>' % (file, pydoc.html.escape(file))
@@ -54,7 +92,7 @@ def html(context=5):
5492
traceback.append('<p>' + level)
5593
continue
5694

57-
# do a fil inspection
95+
# do a file inspection
5896
names = []
5997
def tokeneater(type, token, start, end, line, names=names):
6098
if type == tokenize.NAME and token not in keyword.kwlist:
@@ -68,7 +106,8 @@ def linereader(file=file, lnum=[lnum]):
68106

69107
try:
70108
tokenize.tokenize(linereader, tokeneater)
71-
except IndexError: pass
109+
except IndexError:
110+
pass
72111
lvals = []
73112
for name in names:
74113
if name in frame.f_code.co_varnames:
@@ -83,11 +122,11 @@ def linereader(file=file, lnum=[lnum]):
83122
else:
84123
value = _('<em>undefined</em>')
85124
name = '<em>global</em> <strong>%s</strong>' % name
86-
lvals.append('%s&nbsp;= %s' % (name, value))
125+
lvals.append('%s&nbsp;= %s'%(name, value))
87126
if lvals:
88127
lvals = string.join(lvals, ', ')
89-
lvals = indent + '''
90-
<small><font color="#909090">%s</font></small><br>''' % lvals
128+
lvals = indent + '<small><font color="#909090">%s'\
129+
'</font></small><br>'%lvals
91130
else:
92131
lvals = ''
93132

@@ -124,6 +163,9 @@ def handler():
124163

125164
#
126165
# $Log: not supported by cvs2svn $
166+
# Revision 1.1 2002/08/30 08:28:44 richard
167+
# New CGI interface support
168+
#
127169
# Revision 1.10 2002/01/16 04:49:45 richard
128170
# Handle a special case that the CGI interface tickles. I need to check if
129171
# this needs fixing in python's core.

roundup/cgi/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.18 2002-09-06 05:53:02 richard Exp $
1+
# $Id: client.py,v 1.19 2002-09-06 07:21:31 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -326,7 +326,7 @@ def renderTemplate(self, name, extension, **kwargs):
326326
'<li>'.join(pt._v_errors))
327327
except:
328328
# everything else
329-
return cgitb.html()
329+
return cgitb.pt_html()
330330

331331
def content(self):
332332
''' Callback used by the page template to render the content of
@@ -903,10 +903,9 @@ def searchPermission(self):
903903
return 0
904904
return 1
905905

906-
def XXXremove_action(self, dre=re.compile(r'([^\d]+)(\d+)')):
906+
def remove_action(self, dre=re.compile(r'([^\d]+)(\d+)')):
907907
# XXX I believe this could be handled by a regular edit action that
908908
# just sets the multilink...
909-
# XXX handle this !
910909
target = self.index_arg(':target')[0]
911910
m = dre.match(target)
912911
if m:

roundup/cgi/templating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def getTemplate(dir, name, extension, classname=None, request=None):
9898
# compile the template
9999
templates[key] = pt = RoundupPageTemplate()
100100
pt.write(open(src).read())
101-
pt.id = name
101+
pt.id = filename
102102
pt.mtime = time.time()
103103
return pt
104104

0 commit comments

Comments
 (0)