Jun 29, 2011

Find the real location of the exception

The problem with Django is that there are certain circumstances where it will hide the actual error message and traceback and replace it will a higher level exception, but with the traceback then being where that higher level exception was raised. This is one such case. To try and find the real location of the exception add the following to your WSGI script file.

import traceback 
import sys 
def dump_exception(callable): 
    def wrapper(*args, **kwargs): 
        try: 
            return callable(*args, **kwargs) 
        except: 
            traceback.print_exception(*sys.exc_info()) 
    return wrapper 
import django.core.urlresolvers 
urlresolvers.get_callable = dump_exception(urlresolvers.get_callable) 

This wraps the call which is doing the lookup and will dump out the error message it raises before the traceback gets thrown away.

No comments: