-
-
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
cowboy_req:match_qs with nonempty constraint fails ungracefully on redefined parameters #1435
Comments
So that's not really a bug, the constraints were made to work only with binaries on purpose. They can of course be extended, although I do not think the For But otherwise constraints crashing on invalid input data is the correct behavior. |
For my case I want to assert that each member of the list isn't empty. But fair enough. On reflection I'm not too desperate to put this change into the library, as it's an unusual situation that people might not want to accept by default. I'll define a custom constraint function.
The main issue I had was not the crashing itself, but that it doesn't give a friendly failure reason. Normally when a
If redefined parameters aren't valid then personally I would prefer it to crash with something like:
That way it's more obvious why it's failing, and I don't have to read the library code to figure out what's going on. It's a minor point though. Thanks for maintaining a cool library :) |
Yeah I don't think I can also see the value in not crashing. To be honest this is one of the cases where I wasn't sure what was the best and therefore did not make a decision yet (you'll notice there's no tests for these cases). I think it comes from constraints being added for routing only, initially, where the crash does help. But then they were added to match functions and there it's not exactly the same. I'll soon be adding some good improvements to constraints via the work I'm doing on Farwest. So let's keep this open and I'll consider it when that happens. |
I'm using Cowboy 2.7.0.
Perform a HTTP get on
http://host/path?username=x&username=y
.In the handler, calling
cowboy_req:match_qs([{username, nonempty}], Req)
causes the following crash:I believe that the same will happen for the
int
constraint.Given that
cowboy_req:parse_qs
can handle a redefined parameter, I found this a little surprising (but understandable). I suppose you could modifycowboy_constraints:apply_constraint
to handle this in a few different ways:request_error
like normal).But maybe that's more complicated than you want?
The text was updated successfully, but these errors were encountered: