I'd like some opinions on the existing patch for http://code.djangoproject.com/ticket/3349. This ticket ("If an ImportError occurs within some loaders a rather confusing exception is raised") seeks to address the difficulty of debugging ImportErrors raised in template tag library.
The cause of the problem, generally speaking, is that an exception is caught and a different one is raised, which loses information about the source of the original exception. In this particular case, an ImportError is caught in django.template.get_library, which then raises InvalidTemplateLibrary. InvalidTemplateLibrary is then caught by django.template.defaulttags.load, which raises TemplateSyntaxError. The exception message[1] is kind of confusing, and it's not immediately obvious whether the problem was in Django *finding* the template tag library, or a problem in the library itself, either of which could have caused the original ImportError. The solution in the existing patch is to raise the outer exception (InvalidTemplateLibrary, for the case of get_library) with the *traceback* of the deeper exception. My particular concerns with the patch are, from most to least important: 1. Scope -- the patch generalizes the issue and addresses it throughout Django. Are people ok with that? 2. Design -- The wrap_and_raise function needs to be used not only at the site of the problem, but also possibly at a deeper level in the call stack as well. In this particular case, it needs to be used in both `get_library` and `load` to address the original issue. 3. Design -- Seeing the ImportError's traceback is indeed helpful in identifying the source of the problem. But, it's also kind of weird to have the traceback of an ImportError (ending with the line "import notthere" or whatever) associated with a different exception. 4. Design -- the verbs "wrap" and "raise" in the wrap_and_raise function refer to different objects (the old and new exceptions, respectively). How serious are these issues? Can anyone think of an alternative solution? [1] Depending on the case, you'll see one of the following: 'tag_lib' is not a valid tag library: Could not load template library from django.templatetags.tag_lib, No module named notthere 'tag_lib' is not a valid tag library: Could not load template library from django.templatetags.tag_lib, No module named tag_lib Andrew -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.