Hi David, That looks enormously useful. We've been thinking about ways to store the exact info and provide better errors, but something that requires fewer deep changes (and comfortably fits in an email message) could be a big win today.
Thanks! Kevin On 5/12/06, David Fraser <[EMAIL PROTECTED]> wrote:
Hi Just wanted to post this snippet that I put in our code in case anyone else finds it useful... Basically if an error happens serializing the template, it looks in a traceback and gives you some kind of idea as to which point in the XML file the error happened, by printing out the ancestors of the current XML element. (This is from jToolkit, which is used amongst other things for Pootle, the open source translation web system) Cheers David t = kid.Template(source=source,**context) try: return t.serialize() except Exception, e: tb = sys.exc_info()[2] tb_point = tb while tb_point.tb_next: tb_point = tb_point.tb_next ancestors = tb_point.tb_frame.f_locals.get("ancestors", []) xml_traceback = [] for ancestor in ancestors: if ancestor is None: continue try: ancestor_str = kid.et.tostring(ancestor) except Exception, e: ancestor_str = "(could not convert %s: %s)" % (str(ancestor), str(e)) xml_traceback.append(ancestor_str) context_str = pprint.pformat(context) xml_traceback_str = " " + "\n ".join(xml_traceback) self.errorhandler.logerror("Error converting template: %s\nContext\n%s\nXML Ancestors:\n%s\n%s\n" % (e, context_str, xml_traceback_str, self.errorhandler.traceback_str())) if self.webserver.options.debug: import pdb pdb.post_mortem(tb) ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ kid-template-discuss mailing list kid-template-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kid-template-discuss
-- Kevin Dangoor TurboGears / Zesty News email: [EMAIL PROTECTED] company: http://www.BlazingThings.com blog: http://www.BlueSkyOnMars.com ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ kid-template-discuss mailing list kid-template-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kid-template-discuss