-
-
Notifications
You must be signed in to change notification settings - Fork 85
Description
In
rama/rama-http/src/service/web/router.rs
Lines 530 to 533 in 560c2e3
| #[allow(clippy::expect_used, reason = "TODO later")] | |
| self.routes | |
| .insert(path, vec![(matcher, service)]) | |
| .expect("add route"); |
- duplicate insertion (for the path)
- invalid path
AFAIK the duplication should not be happening as we check if it exists and if so push if it does and only if it doesn't we do insert. Not perfect, but at least that should normally prevent that. The invalid path however could still happen.
Some frameworks like Axum panic for this and many other reasons as they assume that's fine given it will happen when you start the app and so immediately caught. However:
- what if you create the router in a spawned thread? Than that thread will fail silentely (unless you join) making your process with one (router) server less
- what if you create the router not at startup time but dynamically at runtime during any point of the lifetime other than startup?
In all these cases it's a bit crazy to panic... In my opinion panics should only be reserved for very bad stuff like OOM or loco invalid unrecoverable nuclear disaster states. Certainly not for oops I failed to create a router dynamically at runtime...
Even with this context given that doesn't make the solution easier... What to do with this?
- should we just make all methods fallible (e.g.
try_getinstead ofgetas all of them can fail? - should we instead make it a builder like
Request::builderand internally work with aResultso that you only have to deal with the error once? More ergonomic but perhaps a bit weird as you can't really act on that kind of error and it's like a fail all or nothing force move... - work with a more awkward API, perhaps even having to fork the underlying lib so that we can prevent this all together somehow? Or perhaps force people to give verified paths that cannot fail, fine when at runtime, and for static definitions we could provide macro?
- ignore failed inserts? Probably not... seems like a very bad thing to do
None of these options are ideal and perhaps the is another option... We need to fix this before we ship 0.3 as it will be a big breaking change of the router API regardless of the option we choose.