-
Notifications
You must be signed in to change notification settings - Fork 128
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
Consider spliting validate
in two methods
#140
Comments
Why not just make the synchronous one look or act async? i.e.,
See this from the Node.js manual/docs: http://nodejs.org/docs/latest/api/process.html#process_process_nexttick_callback |
You could also push the entire |
Perhaps it's also a good time to point out that the behaviour of |
@chrisfosterelli -- why is it a huge pain? You just have to wrap it in a try/catch. It's the same as a |
@neumino Not calling I've been playing around with the validation logic now, and it seems that the promise is rejected in some cases but an exception is thrown in others. If I pass in an invalid date, an exception is thrown. The other cases seem to reject the promise. Is this expected behaviour? |
@chrisfosterelli -- There is a try/catch wrapping the validate in save, so it shouldn't throw If it does, could you provide a script to reproduce that? Also as far as I know, it's not a bad pattern to throw. It's bad to throw when you don't catch it, and/or don't set up a domain. From https://www.joyent.com/developers/node/design/errors
Also in the case of |
@neumino The difference for me would be that the responsibility of However, you're definitely right that the nodejs docs appear to explicitly outline user input validation as one of the only use cases for throwing, so that seems like fair reasoning to me then! I won't distract this thread anymore from considering whether or not to split |
Thanks @chrisfosterelli for chiming in. It makes sense, I can see why returning a value can make more sense. Currently thinky returns the first error, and some people would prefer to return all of them. Maybe that would be a good time to revisit whether validate should throw or return a value since return multiple errors is kind of cumbersome. |
That was kind of done some time ago. |
I thought it was insane to do it, and now I kind of regret it.
We should split
validate
in two methods, one synchronous and one asynchronousSee #113 (comment)
The text was updated successfully, but these errors were encountered: