Fix some launch error handling in tests and examples.

This commit is contained in:
Jeb Rosen 2019-09-08 13:53:53 -07:00 committed by Sergio Benitez
parent a0d2651e38
commit 77a64c73bb
2 changed files with 22 additions and 12 deletions

View File

@ -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);
/// # }
/// ```
///

View File

@ -19,13 +19,14 @@ fn not_found(req: &rocket::Request<'_>) -> content::Html<String> {
}
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);
};
}