Add error handling tests and fix them