Handle relation changeset error in one place#2725
Merged
Merged
Conversation
wojtekmach
reviewed
Oct 1, 2018
| {changes, errors, valid?} | ||
| :error -> | ||
| error = {key, {"is invalid", [type: expected_relation_type(relation)]}} | ||
| {:error, reason} -> |
Member
There was a problem hiding this comment.
nitpick: reason is usually an atom/string/etc, in this case it's {message, metadata_kw}. It's not ideal because we're using word error a lot here, but maybe the variable should be called error still (which matches t:Ecto.Changeset.error/0 type)?
btw, thanks for this PR <3
Member
Author
There was a problem hiding this comment.
Thanks for pointing it out! It's fixed.
Member
|
❤️ 💚 💙 💛 💜 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR intended to fix #2722, but ended up together with some slight refactoring of
Ecto.Changeset.Relationmodule.cast/4andchange/3have been changed to return{:error, Ecto.Changeset.error()}instead of just:error, making error handling easier for the caller. Error messages and metadata are also encapsulated at where the data get casted/changed, making future improvements of these information, e.g based on relation type, relatively easier.