diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs index 038094cd..ba425642 100644 --- a/core/lib/src/rocket.rs +++ b/core/lib/src/rocket.rs @@ -212,6 +212,7 @@ impl Rocket { self } + #[track_caller] fn load<'a, B, T, F, M>(mut self, kind: &str, base: B, items: Vec, m: M, f: F) -> Self where B: TryInto> + Clone + fmt::Display, B::Error: fmt::Display, @@ -219,13 +220,15 @@ impl Rocket { F: Fn(&mut Self, T), T: Clone + fmt::Display, { - let mut base = base.clone().try_into() - .map(|origin| origin.into_owned()) - .unwrap_or_else(|e| { + let mut base = match base.clone().try_into() { + Ok(origin) => origin.into_owned(), + Err(e) => { error!("invalid {} base: {}", kind, Paint::white(&base)); error_!("{}", e); + info_!("{} {}", Paint::white("in"), std::panic::Location::caller()); panic!("aborting due to {} base error", kind); - }); + } + }; if base.query().is_some() { warn!("query in {} base '{}' is ignored", kind, Paint::white(&base)); @@ -233,12 +236,15 @@ impl Rocket { } for unmounted_item in items { - let item = m(&base, unmounted_item.clone()) - .unwrap_or_else(|e| { + let item = match m(&base, unmounted_item.clone()) { + Ok(item) => item, + Err(e) => { error!("malformed URI in {} {}", kind, unmounted_item); error_!("{}", e); + info_!("{} {}", Paint::white("in"), std::panic::Location::caller()); panic!("aborting due to invalid {} URI", kind); - }); + } + }; f(&mut self, item) } @@ -300,6 +306,7 @@ impl Rocket { /// rocket::build().mount("/hello", vec![hi_route]) /// } /// ``` + #[track_caller] pub fn mount<'a, B, R>(self, base: B, routes: R) -> Self where B: TryInto> + Clone + fmt::Display, B::Error: fmt::Display, diff --git a/core/lib/src/route/route.rs b/core/lib/src/route/route.rs index 8c0d7edd..a069e806 100644 --- a/core/lib/src/route/route.rs +++ b/core/lib/src/route/route.rs @@ -213,6 +213,7 @@ impl Route { /// assert_eq!(index.method, Method::Get); /// assert_eq!(index.uri, "/"); /// ``` + #[track_caller] pub fn new(method: Method, uri: &str, handler: H) -> Route { Route::ranked(None, method, uri, handler) } @@ -242,6 +243,7 @@ impl Route { /// assert_eq!(foo.method, Method::Post); /// assert_eq!(foo.uri, "/foo?bar"); /// ``` + #[track_caller] pub fn ranked(rank: R, method: Method, uri: &str, handler: H) -> Route where H: Handler + 'static, R: Into>, { diff --git a/core/lib/src/route/uri.rs b/core/lib/src/route/uri.rs index b8e00a9a..b3d1900e 100644 --- a/core/lib/src/route/uri.rs +++ b/core/lib/src/route/uri.rs @@ -129,6 +129,7 @@ impl<'a> RouteUri<'a> { /// Create a new `RouteUri`. /// /// Panics if `base` or `uri` cannot be parsed as `Origin`s. + #[track_caller] pub(crate) fn new(base: &str, uri: &str) -> RouteUri<'static> { Self::try_new(base, uri).expect("Expected valid URIs") }