-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Should Mappers returns Result<T> signature? #9
Comments
I'd guess it's to simplify code in other areas. Otherwise every time you load an item from your persistence layer you'd have to perform error checking but I've actually gone down the route of returning Result objects from the Mapper functions. |
@roylee0704 Domain classes must throw an Exeption, for fail fast principle(FailFast @ MartinFowler). Result monad is well suited for validating data before it is passed to domain class methods. If an invalid state is passed to Mapper, and if this is the expected case, for example, when we added a new required field to the database, but only users can fill it out, we need to create an additional field, for example, CustomerOld, and wait for the moment when we can delete it without causing exceptions. |
@NikitaIT I have to disagree with you. I think you are misinterpreting fail fast principle as "must throw an Exception", even in the document you have attached, Matrin Fowler's main complaint is returning partially correct or default values that allow the system to continue operating in an invalid state. I believe that the Result class handles the principle in the same was as an exception without destroying the fluidity of the system. You are not able to act on a failed Result object in the same way as the object type and your code is forced to handle it unlike exceptions which are frequently overlooked, undocumented and badly handled. Either way, the current implementation within the project of returning a null value on the bad mapping neither fails nor is it visible. |
@apparatusdeus This is similar to "First think, then speak" for code. This makes it possible to validate only IO, and as soon as the data crosses the boundary, we can trust the code, instead of trying.
|
white-label/src/modules/vinyl/mappers/VinylMap.ts
Line 18 in 8d18135
Is there is a reason why it's not returning Result ?
The text was updated successfully, but these errors were encountered: