From b0d6d625fe44fdeb751575bb040af127b8d0831f Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Sun, 8 Sep 2019 13:53:53 -0700 Subject: [PATCH] Fix some launch error handling in tests and examples. --- core/lib/src/error.rs | 25 +++++++++++++++++-------- examples/errors/src/main.rs | 9 +++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/lib/src/error.rs b/core/lib/src/error.rs index 12bd961ea8..e9ed769637 100644 --- a/core/lib/src/error.rs +++ b/core/lib/src/error.rs @@ -51,17 +51,26 @@ pub enum LaunchErrorKind { /// as inspected; a subsequent `drop` of the value will _not_ result in a panic. /// The following snippet illustrates this: /// -// TODO.async This isn't true any more, as `.launch()` now returns a -// `Result<(), crate::error::Error>`, which could also be a runtime error. -/// ```rust,ignore +/// ```rust +/// use rocket::error::Error; +/// /// # if false { -/// let error = rocket::ignite().launch(); +/// if let Err(error) = rocket::ignite().launch() { +/// match error { +/// Error::Launch(error) => { +/// // This case is only reached if launching failed. This println "inspects" the error. +/// println!("Launch failed! Error: {}", error); /// -/// // This line is only reached if launching failed. This "inspects" the error. -/// println!("Launch failed! Error: {}", error); +/// // This call to drop (explicit here for demonstration) will do nothing. +/// drop(error); +/// } +/// Error::Run(error) => { +/// // This case is reached if launching succeeds, but the server had a fatal error later +/// println!("Server failed! Error: {}", error); +/// } +/// } +/// } /// -/// // This call to drop (explicit here for demonstration) will do nothing. -/// drop(error); /// # } /// ``` /// diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs index 8cad7a21d9..8ad4bc353a 100644 --- a/examples/errors/src/main.rs +++ b/examples/errors/src/main.rs @@ -19,13 +19,14 @@ fn not_found(req: &rocket::Request<'_>) -> content::Html { } fn main() { - let e = rocket::ignite() + let result = rocket::ignite() // .mount("/", routes![hello, hello]) // uncoment this to get an error .mount("/", routes![hello]) .register(catchers![not_found]) .launch(); - println!("Whoops! Rocket didn't launch!"); - // TODO.async Uncomment the following line once `.launch()`'s error type is determined. - // println!("This went wrong: {}", e); + if let Err(e) = result { + println!("Whoops! Rocket didn't launch!"); + println!("This went wrong: {:?}", e); + }; }