Fix error handling in testcase