DEV Community

Discussion on: Returning type-safe & non-nil failure in Crystal?

Collapse
 
blacksmoke16 profile image
Blacksmoke16 • Edited

I think it partially depends on the context of the method/application. IMO, I feel you should consider the implication of what should happen if the method returns nil, not just handling it for sake of handling it.

If this was for an API, I would expect that a 404 exception would get returned to the user saying like "hey this user doesn't exist".

However that logic doesn't have to live within this method. Having this method return Nil | User is perfectly fine; where the check can happen higher up in the process.