-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Collection of validation errors #433
Conversation
I wonder whether we should break backwards compatibility and raise the collection instead of adding the option and raising the first validation error? Another option is to raise the first error if there's one or the collection if there're many. Thoughts? |
Please also update CHANGELOG and README. |
Thanks for the feedback. I would preserve backwards compatibility if you don't plan to release a new major version in the near future. In the next major version we could raise the collection by default (and remove the flag |
I'd rather break backward compatibility here than introduce an option that will have to be removed. Will bump the major version. |
I'm okay with that. I just removed the backwards compatibility and found a bug along the way where each presence validator was registered twice (cf. 3723c99). The only gripe (no pun intended) I have is that the base |
I think Am I missing anything? |
Ok. I'll look into it as soon as I find the time. |
@dblock, @stevschmid , any updates ? This feature would be really handy. |
@stevschmid If you don't have time to finish it, LMK, I'll try to find some this week. |
@dblock I was absent the last 3 weeks. I should be able to finish it this week. |
I removed the status, but I'm very unhappy with the result. In my opinion, the whole validation system is badly designed. My pull request would be a hack on top of it and make the system even more fragile:
At the end of the day, you are interested in all the validation errors, optimally grouped by the parameter name. Rails solves the collection of the validation errors very elegantly with ActiveModel::Errors. I think it would be better to replace the whole validation system by something more robust and use the Rails way as an inspiration. What do you think? |
I think this implementation is better than what we had before, so I am going to merge it. I don't want to launch a debate on exceptions vs. non-exceptions, but my philosophy is that the burden of checking should not be put on the developer, at least not by default. I side with the idea that "developers should write less code", and isn't that the whole purpose of the library like Grape? I would be open to replacing the validation system with something better if it's actually better :) |
I have a more polished version. I'll push it tomorrow. |
A new version of the gem should be released as soon as possible after this merge. I spent hours (more like 15 minutes) to figure out that the documentation is wrong after this merge. Only the old "Grape::Exceptions::Validation" (without s) works in the current release of the gem. |
We added the ability to collect the validation errors in order to display them at once (e.g. in a form).
Usage:
We made sure that the exception handling is backwards compatible.
What do you think about it?