Skip to content

Commit 91c12cd

Browse files
committed
Fix some launch error handling in tests and examples.
1 parent 02d5893 commit 91c12cd

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

core/lib/src/error.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,26 @@ pub enum LaunchErrorKind {
5151
/// as inspected; a subsequent `drop` of the value will _not_ result in a panic.
5252
/// The following snippet illustrates this:
5353
///
54-
// TODO.async This isn't true any more, as `.launch()` now returns a
55-
// `Result<(), crate::error::Error>`, which could also be a runtime error.
56-
/// ```rust,ignore
54+
/// ```rust
55+
/// use rocket::error::Error;
56+
///
5757
/// # if false {
58-
/// let error = rocket::ignite().launch();
58+
/// if let Err(error) = rocket::ignite().launch() {
59+
/// match error {
60+
/// Error::Launch(error) => {
61+
/// // This case is only reached if launching failed. This println "inspects" the error.
62+
/// println!("Launch failed! Error: {}", error);
5963
///
60-
/// // This line is only reached if launching failed. This "inspects" the error.
61-
/// println!("Launch failed! Error: {}", error);
64+
/// // This call to drop (explicit here for demonstration) will do nothing.
65+
/// drop(error);
66+
/// }
67+
/// Error::Run(error) => {
68+
/// // This case is reached if launching succeeds, but the server had a fatal error later
69+
/// println!("Server failed! Error: {}", error);
70+
/// }
71+
/// }
72+
/// }
6273
///
63-
/// // This call to drop (explicit here for demonstration) will do nothing.
64-
/// drop(error);
6574
/// # }
6675
/// ```
6776
///

examples/errors/src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ fn not_found(req: &rocket::Request<'_>) -> content::Html<String> {
1919
}
2020

2121
fn main() {
22-
let e = rocket::ignite()
22+
let result = rocket::ignite()
2323
// .mount("/", routes![hello, hello]) // uncoment this to get an error
2424
.mount("/", routes![hello])
2525
.register(catchers![not_found])
2626
.launch();
2727

28-
println!("Whoops! Rocket didn't launch!");
29-
// TODO.async Uncomment the following line once `.launch()`'s error type is determined.
30-
// println!("This went wrong: {}", e);
28+
if let Err(e) = result {
29+
println!("Whoops! Rocket didn't launch!");
30+
println!("This went wrong: {:?}", e);
31+
};
3132
}

0 commit comments

Comments
 (0)