hook to email errors
fix to email errors and added debug hook to raise error.