Type-safe error handling