malthe / chameleon

Fast HTML/XML template engine for Python
https://chameleon.readthedocs.io
Other
176 stars 64 forks source link

Traceback errors almost useless #291

Open frapell opened 5 years ago

frapell commented 5 years ago

I am testing Plone 5.2 RC1, which brings in Chameleon 3.6, and I am finding the tracebacks for template errors to have very few useful information in order to find what the problem is and fix it...

Here's an example traceback

Traceback (innermost last):                                                                                                                        
  Module ZPublisher.WSGIPublisher, line 142, in transaction_pubevents                                                                              
  Module ZPublisher.WSGIPublisher, line 295, in publish_module                                                                                     
  Module ZPublisher.WSGIPublisher, line 229, in publish                                                                                            
  Module ZPublisher.mapply, line 85, in mapply                                                                                                     
  Module ZPublisher.WSGIPublisher, line 57, in call_object                                                                                         
  Module zope.browserpage.simpleviewclass, line 41, in __call__                                                                                    
  Module Products.Five.browser.pagetemplatefile, line 125, in __call__                                                                             
  Module Products.Five.browser.pagetemplatefile, line 60, in __call__
  Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  Module Products.PageTemplates.engine, line 90, in __call__
  Module z3c.pt.pagetemplate, line 173, in render
  Module chameleon.zpt.template, line 306, in render
  Module chameleon.template, line 209, in render
  Module chameleon.utils, line 75, in raise_with_traceback
  Module chameleon.template, line 187, in render
  Module 725786e2c8a31ded6b7684c282468abe, line 1255, in render
  Module 577383cc104600ed6eaa68e46f6714e9, line 685, in render_master
  Module 577383cc104600ed6eaa68e46f6714e9, line 1275, in render_content
  Module 725786e2c8a31ded6b7684c282468abe, line 441, in __fill_main
TypeError: 'NoneType' object is not iterable

 - Expression: "context/main_template/macros/master"
 - Filename:   ... t.plone/src/test/plone/browser/example_view.pt
 - Location:   (line 6: col 21)
 - Source:     ... etal:use-macro="context/main_template/macros/master"
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  template: <ViewPageTemplateFile - at 0x7fa0ff6d3240>
               options: {...} (0)
               args: <tuple - at 0x7fa112653048>
               nothing: <NoneType - at 0xa1e6d0>
               modules: <_SecureModuleImporter - at 0x7fa10a40f588>
               request: <WSGIRequest - at 0x7fa103d04a58>
               view: <SimpleViewClass from /vagrant/src/test.plone/src/test/plone/browser/example_view.pt example_view at 0x7fa
0ff376198>
               context: <ImplicitAcquisitionWrapper Plone at 0x7fa1060dad38>
               views: <ViewMapper - at 0x7fa0ff713e10>
               here: <ImplicitAcquisitionWrapper Plone at 0x7fa1060dad38>
               container: <ImplicitAcquisitionWrapper Plone at 0x7fa1060dad38>
               root: <ImplicitAcquisitionWrapper  at 0x7fa1060da5e8>
               traverse_subpath: <list - at 0x7fa105d33908>
               user: <ImplicitAcquisitionWrapper - at 0x7fa10a2bd240>
               default: <object - at 0x7fa1113efb10>
               repeat: {...} (0)
               loop: {...} (1)
               wrapped_repeat: <SafeMapping - at 0x7fa105b57808>
               target_language: <NoneType - at 0xa1e6d0>
               translate: <function translate at 0x7fa103786620>
               macroname: master

The only bit useful in there is knowing that the template that blows up is /vagrant/src/test.plone/src/test/plone/browser/example_view.pt...

The actual issue has nothing to do with the master macro and neither it is located at line 6, column 21.

The actual issue is located at line 53 tal:define="items python: [i for i in matches];" while matches being None.

I have tried looking around in order to find a way to improve these tracebacks, but I couldn't find anything... Also tried setting CHAMELEON_DEBUG to 1 as explained in https://chameleon.readthedocs.io/en/latest/configuration.html#development but didn't improve anything...

malthe commented 5 years ago

Maybe related to #259.

fschulze commented 2 weeks ago

Macro use/inclusion swallows exceptions. I traced it a while ago, but didn't make notes. I was able to restore the traceback with some fancy attribute chain walking in that place. Could have been here: https://github.com/malthe/chameleon/blob/da3cc82f12948d43d7c23daf00529c5405392b9a/src/chameleon/compiler.py#L1205