You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to extract a extension of a State that ist not .layer()d on to the app,
a HTTP 500 is returned when querying the handler.
$ curl http://localhost:3000/
Missing request extension: Extension of type`alloc::sync::Arc<i32>` was not found. Perhaps you forgot to add it? See `axum::Extension`.
To validate whether or not all endpoints have valid extension types, every single endpoint has to be queried at runtime.
This feels frustrating and avoidable.
I assume many projects don't build their paths dynamically, but define the entire application at compile time.
In these cases it feels like it could be validated at compile time (maybe with macros? other ways?) to fit the
"If it compiles, it works" philosophy.
I understand that this is probably not an easy implementable solution.
However, validating extension types of endpoints when starting, is a simpler logic and would be nice to have available.
Proposal
Add a method to axum::Router which allows for validating handler extensions.
let state = State::new();let app = Router::new().route("/", service.get(handler)).layer(Extension(state)).validate_handler_extension_types()?;
Alternatively app could require to have the layer mounted before adding routes
requiring this extension type.
let state = State::new();let app = Router::new().layer(Extension(state)).route("/", service.get(handler));// panic or Err(x) if layer would not have been mounted
Alternatives
Doing nothing
Documenting a way to figure out if all endpoints are using extractable extensions.
The text was updated successfully, but these errors were encountered:
Feature Request
Motivation
When trying to extract a extension of a
State
that ist not.layer()
d on to theapp
,a HTTP 500 is returned when querying the handler.
To validate whether or not all endpoints have valid extension types, every single endpoint has to be queried at runtime.
This feels frustrating and avoidable.
I assume many projects don't build their paths dynamically, but define the entire application at compile time.
In these cases it feels like it could be validated at compile time (maybe with macros? other ways?) to fit the
"If it compiles, it works" philosophy.
I understand that this is probably not an easy implementable solution.
However, validating extension types of endpoints when starting, is a simpler logic and would be nice to have available.
Proposal
Add a method to
axum::Router
which allows for validating handler extensions.Alternatively
app
could require to have the layer mounted before adding routesrequiring this extension type.
Alternatives
The text was updated successfully, but these errors were encountered: