diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index de706cfe..256a8b25 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -42,8 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 relaxed so the response type must implement `IntoResponse` rather than being a literal `Response` - **change:** axum's MSRV is now 1.60 ([#1239]) +- **fixed:** Annotate panicking functions with `#[track_caller]` so the error + message points to where the user added the invalid router, rather than + somewhere internally in axum ([#1248]) -[#1171]: https://github.com/tokio-rs/axum/pull/1171 [#1077]: https://github.com/tokio-rs/axum/pull/1077 [#1086]: https://github.com/tokio-rs/axum/pull/1086 [#1088]: https://github.com/tokio-rs/axum/pull/1088 @@ -52,7 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#1130]: https://github.com/tokio-rs/axum/pull/1130 [#1135]: https://github.com/tokio-rs/axum/pull/1135 [#1152]: https://github.com/tokio-rs/axum/pull/1152 +[#1171]: https://github.com/tokio-rs/axum/pull/1171 [#1239]: https://github.com/tokio-rs/axum/pull/1239 +[#1248]: https://github.com/tokio-rs/axum/pull/1248 [#924]: https://github.com/tokio-rs/axum/pull/924 # 0.5.10 (28. June, 2022) diff --git a/axum/src/routing/method_routing.rs b/axum/src/routing/method_routing.rs index f948fab7..0aca7daf 100644 --- a/axum/src/routing/method_routing.rs +++ b/axum/src/routing/method_routing.rs @@ -205,6 +205,7 @@ macro_rules! chained_service_fn { $name:ident, $method:ident ) => { $(#[$m])+ + #[track_caller] pub fn $name(self, svc: S) -> Self where S: Service, Error = E> @@ -268,6 +269,7 @@ macro_rules! chained_handler_fn { $name:ident, $method:ident ) => { $(#[$m])+ + #[track_caller] pub fn $name(self, handler: H) -> Self where H: Handler, @@ -577,6 +579,7 @@ where /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` + #[track_caller] pub fn on(self, filter: MethodFilter, handler: H) -> Self where H: Handler, @@ -689,6 +692,7 @@ impl MethodRouter { /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` + #[track_caller] pub fn on_service(self, filter: MethodFilter, svc: S) -> Self where S: Service, Error = E> + Clone + Send + 'static, @@ -783,8 +787,10 @@ impl MethodRouter { } #[doc = include_str!("../docs/method_routing/merge.md")] + #[track_caller] pub fn merge(mut self, other: MethodRouter) -> Self { // written using inner functions to generate less IR + #[track_caller] fn merge_inner(name: &str, first: Option, second: Option) -> Option { match (first, second) { (Some(_), Some(_)) => panic!( @@ -796,6 +802,7 @@ impl MethodRouter { } } + #[track_caller] fn merge_fallback( fallback: Fallback, fallback_other: Fallback, @@ -843,6 +850,7 @@ impl MethodRouter { self.layer(HandleErrorLayer::new(f)) } + #[track_caller] fn on_service_boxed_response_body(mut self, filter: MethodFilter, svc: S) -> Self where S: Service, Error = E> + Clone + Send + 'static, diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index 01db8e55..8c4559d2 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -114,6 +114,7 @@ where } #[doc = include_str!("../docs/routing/route.md")] + #[track_caller] pub fn route(mut self, path: &str, service: T) -> Self where T: Service, Error = Infallible> + Clone + Send + 'static, @@ -167,6 +168,7 @@ where self } + #[track_caller] fn set_node(&mut self, path: &str, id: RouteId) { let mut node = Arc::try_unwrap(Arc::clone(&self.node)).unwrap_or_else(|node| (*node).clone()); @@ -177,6 +179,7 @@ where } #[doc = include_str!("../docs/routing/nest.md")] + #[track_caller] pub fn nest(mut self, mut path: &str, svc: T) -> Self where T: Service, Error = Infallible> + Clone + Send + 'static, @@ -216,6 +219,7 @@ where } #[doc = include_str!("../docs/routing/merge.md")] + #[track_caller] pub fn merge(mut self, other: R) -> Self where R: Into>,