def less_shitty_error_messages(func):
 @wraps(func)
 def inner(self, sql, *args, **kwargs):
  try:
   return func(self, sql, *args, **kwargs)
  except Exception as e:
   exc_info = sys.exc_info()
   msg = '{}\nSQL: {}'.format(repr(e), sql)
   six.reraise(exc_info[0], exc_info[0](msg), exc_info[2])
 return inner

def less_shitty_error_messages ( func ) : @ wraps ( func ) def inner ( self , sql , * args , ** kwargs ) : try : return func ( self , sql , * args , ** kwargs ) except Exception as e : exc_info = sys . exc_info ( ) msg = '{}\nSQL: {}' . format ( repr ( e ) , sql ) six . reraise ( exc_info [ 0 ] , exc_info [ 0 ] ( msg ) , exc_info [ 2 ] ) return inner
wraps functions where the first param is a sql statement and enforces any exceptions thrown will also contain the statement in the message .