[Zope] Confusing "sqlvar" error message

Dieter Maurer dieter@handshake.de
Fri, 4 Aug 2000 22:25:51 +0200 (CEST)


Today, I analysed a confusing error message from "dtml-sqlvar".

	SQL query template:
		....
		<dtml-sqlvar "_[name]" type=string>
		....

	reported: "missing input variable: _[name]"


Of cause, I did not expect that such an input variable should
be necessary and I suspected the DTML parser not to
see the "..." around "_[name]".


After analysis, the explanation was simple:

	SQLVar.render is a bit stupid in its error handling:

        try:
            expr=self.expr
            if type(expr) is type(''): v=md[expr]
            else: v=expr(md)
        except:
            if args.has_key('optional') and args['optional']: return 'null'
            raise 'Missing Input', 'Missing input variable, <em>%s</em>' % name


        This error handling is only senseful for "type(expr) == type('')",
	i.e. for plain variable access.
	For true expressions, the original exception would be
	*much* more useful.

	In my case, unwrapping the "try ... except ..."
	produced "KeyError: FOLLUP_UP",
	an obvious type (FOLLOW_UP rather than FOLLUP_UP).


	Thus, the above exception handling should become:

        except:
            if args.has_key('optional') and args['optional']: return 'null'
	    if type(self.expr) != type(''): raise
            raise 'Missing Input', 'Missing input variable, <em>%s</em>' % name
	
		  
I will put it into the collector.


Dieter