Open fishtreesugar opened 1 week ago
I definitely contemplated this. It should probably change to new
outputting a tuple, and new!
raising. Then maybe have an option in new
like :ignore_errors
. Thoughts?
It should probably change to new outputting a tuple, and new! raising.
Yes, I think it should be closer to the convection of Elixir's stdlib, e.g. fetch/2
v.s. fetch!/2
Then maybe have an option in new like :ignore_errors. Thoughts?
In my opinion, it shouldn't allow an easy way to skip the error. 😂
FWIW, thank you for your quick response!
Currently, there are two APIs for constructing a struct:
new
andnew!
. Thenew
function ignores changeset errors and returns the struct regardless, whilenew!
raises anArgumentError
when there are changeset errors. In Elixir, usingwith
for error handling is common:For cases with no changeset errors,
parse
will return{:ok, struct}
; otherwise, it will return{:error, changeset}
. Of course, the name of the API could be discussed further. To align with the "Parse, don't validate" slogan, it would be beneficial ifflint
provided such an API.