Improve error handling in serialization tests.