Skip to content

Commit

Permalink
Fix some launch error handling in tests and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
jebrosen committed Sep 21, 2019
1 parent 25adb9d commit b0d6d62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
25 changes: 17 additions & 8 deletions core/lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// # }
/// ```
///
Expand Down
9 changes: 5 additions & 4 deletions examples/errors/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

0 comments on commit b0d6d62

Please sign in to comment.