-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Panic when a route is added with different path params #1762
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
Panic when a route is added with different path params #1762
Conversation
From now, Echo panics if a route that was already added, is added again but for a different HTTP method and the path params are different. e.g. GET /translation/:lang -> Added OK PUT /translation/:lang -> Added OK DELETE /translation/:id -> Panic Partially Fixes labstack#1726 labstack#1744
Codecov Report
@@ Coverage Diff @@
## master #1762 +/- ##
==========================================
- Coverage 89.75% 89.74% -0.02%
==========================================
Files 32 32
Lines 2675 2671 -4
==========================================
- Hits 2401 2397 -4
Misses 175 175
Partials 99 99
Continue to review full report at Codecov.
|
This is place where maybe it would be better if route adding would return an error. Panicing is not nice but we already do it for some other things and assuming that routes are defined only on application startup - we can turn a blind eye. by returning an error This is something to think about future. |
I'm not a big fan of panic also, but as @aldas mentioned, we are already doing it and I preferred to get something quickly to at least move forward with those two issues. Because this PR is tagged as v5, we have time to get it in shape. If we agree on it, I can try to change the Router to return errors (at least in this two panic cases, and later on we can add more errors) |
mmm, if its v5 then I have additional ideas for router - make router implement 2 interfaces and reference router by those interfaces
this would make possible to add/change router implementations in future easier. 2 interfaces to explicitly separate 2 phases of router lifecycle for implementor. This is very far fetched idea but you could build/return different implementations of router depending on added routes characteristics - for example router for single static route vs. router handling thousands of routes efficiently. I admit that 99.9999% cases you do need this but by adding those interfaces does not increase complexity of code much. might be good idea to start some thread in discussions to link all those ideas @lammel (where first post has list of things and verdic on those) |
Also moving Route information from Echo to Router. This change also enabled moving the Reverse method to the Router.
I uploaded a proposal of the changes mentioned by @aldas. The builds are not passing due to linting errors (I need to add proper comments and rename some things), but the tests and benchmarks pass locally. |
This definitely needs some planning and research. For example Also there is use case how newly created route is used I think we should start by listing API changes and discuss pros and cons. Determine what will be backwards compatible and what not. probably should separate this problem - 2 routes with same prefix but with different path variable names and Router API changes. |
@pafuent maybe it would be better to follow #1306 route and PR #1430 implementation. I personally do not think having different param names for same prefix is conceptually correct (definitely in RESTful world) but seems that this is quite common problem for users. #1430 seems to be one way to do it but I'm not really sure how well it handles adding routes in different order and adding routes with groups and without group with same prefix. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions. |
I'll leave it closed. This is revised in |
From now, Echo panics if a route that was already added, is added again
but for a different HTTP method and the path params are different.
e.g.
GET /translation/:lang -> Added OK
PUT /translation/:lang -> Added OK
DELETE /translation/:id -> Panic
Partially Fixes #1726 #1744