def less_shitty_error_messages(func):
"""
Wraps functions where the first param is a SQL statement and enforces
any exceptions thrown will also contain the statement in the message.
"""
@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(
e.message,
sql,
)
six.reraise(exc_info[0], exc_info[0](msg), exc_info[2])
return inner
评论列表
文章目录