Skip to content

Commit d767694

Browse files
committed
Remove 'Error' panic-on-drop behavior.
Instead, the `#[launch]` attribute traces the error and panics, replicating the old behavior in the common case.
1 parent 8a1c91b commit d767694

File tree

17 files changed

+274
-262
lines changed

17 files changed

+274
-262
lines changed

contrib/dyn_templates/src/fairing.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rocket::{Rocket, Build, Orbit};
22
use rocket::fairing::{self, Fairing, Info, Kind};
3+
use rocket::figment::{Source, value::magic::RelativePathBuf};
34

45
use crate::context::{Callback, Context, ContextManager};
56
use crate::template::DEFAULT_TEMPLATE_DIR;
@@ -31,8 +32,6 @@ impl Fairing for TemplateFairing {
3132
/// template engines. In debug mode, the `ContextManager::new` method
3233
/// initializes a directory watcher for auto-reloading of templates.
3334
async fn on_ignite(&self, rocket: Rocket<Build>) -> fairing::Result {
34-
use rocket::figment::value::magic::RelativePathBuf;
35-
3635
let configured_dir = rocket.figment()
3736
.extract_inner::<RelativePathBuf>("template_dir")
3837
.map(|path| path.relative());
@@ -55,14 +54,13 @@ impl Fairing for TemplateFairing {
5554
}
5655

5756
async fn on_liftoff(&self, rocket: &Rocket<Orbit>) {
58-
use rocket::{figment::Source, yansi::Paint};
59-
6057
let cm = rocket.state::<ContextManager>()
6158
.expect("Template ContextManager registered in on_ignite");
6259

63-
info!("{}{}:", "📐 ".emoji(), "Templating".magenta());
64-
info_!("directory: {}", Source::from(&*cm.context().root).primary());
65-
info_!("engines: {:?}", Engines::ENABLED_EXTENSIONS.primary());
60+
info_span!("templating" [icon = "📐"] => {
61+
info!(directory = %Source::from(&*cm.context().root));
62+
info!(engines = ?Engines::ENABLED_EXTENSIONS);
63+
});
6664
}
6765

6866
#[cfg(debug_assertions)]
@@ -72,5 +70,4 @@ impl Fairing for TemplateFairing {
7270

7371
cm.reload_if_needed(&self.callback);
7472
}
75-
7673
}

core/codegen/src/attribute/entry/launch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use proc_macro2::{TokenStream, Span};
44

55
use super::EntryAttr;
66
use crate::attribute::suppress::Lint;
7-
use crate::exports::mixed;
7+
use crate::exports::{mixed, _error, _ExitCode};
88

99
/// `#[rocket::launch]`: generates a `main` function that calls the attributed
1010
/// function to generate a `Rocket` instance. Then calls `.launch()` on the
@@ -106,14 +106,14 @@ impl EntryAttr for Launch {
106106

107107
let (vis, mut sig) = (&f.vis, f.sig.clone());
108108
sig.ident = syn::Ident::new("main", sig.ident.span());
109-
sig.output = syn::ReturnType::Default;
109+
sig.output = syn::parse_quote!(-> #_ExitCode);
110110
sig.asyncness = None;
111111

112112
Ok(quote_spanned!(block.span() =>
113113
#[allow(dead_code)] #f
114114

115115
#vis #sig {
116-
let _ = ::rocket::async_main(#launch);
116+
#_error::Error::report(::rocket::async_main(#launch))
117117
}
118118
))
119119
}

core/codegen/src/exports.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ define_exported_paths! {
6969
_request => ::rocket::request,
7070
_response => ::rocket::response,
7171
_route => ::rocket::route,
72+
_error => ::rocket::error,
7273
_catcher => ::rocket::catcher,
7374
_sentinel => ::rocket::sentinel,
7475
_form => ::rocket::form::prelude,
@@ -84,6 +85,7 @@ define_exported_paths! {
8485
_Box => ::std::boxed::Box,
8586
_Vec => ::std::vec::Vec,
8687
_Cow => ::std::borrow::Cow,
88+
_ExitCode => ::std::process::ExitCode,
8789
BorrowMut => ::std::borrow::BorrowMut,
8890
Outcome => ::rocket::outcome::Outcome,
8991
FromForm => ::rocket::form::FromForm,

core/lib/src/config/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ pub fn bail_with_config_error<T>(error: figment::Error) -> T {
433433
}
434434

435435
#[doc(hidden)]
436-
// FIXME: Remove this funtion.
436+
// FIXME: Remove this function.
437437
pub fn pretty_print_error(error: figment::Error) {
438438
error.trace_error()
439439
}

core/lib/src/config/tests.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,22 @@ fn test_precedence() {
340340

341341
#[test]
342342
#[cfg(feature = "secrets")]
343-
#[should_panic]
344343
fn test_err_on_non_debug_and_no_secret_key() {
345344
figment::Jail::expect_with(|jail| {
346345
jail.set_env("ROCKET_PROFILE", "release");
347346
let rocket = crate::custom(Config::figment());
348-
let _result = crate::local::blocking::Client::untracked(rocket);
347+
crate::local::blocking::Client::untracked(rocket).expect_err("release secret key");
349348
Ok(())
350349
});
351350
}
352351

353352
#[test]
354353
#[cfg(feature = "secrets")]
355-
#[should_panic]
356354
fn test_err_on_non_debug2_and_no_secret_key() {
357355
figment::Jail::expect_with(|jail| {
358356
jail.set_env("ROCKET_PROFILE", "boop");
359357
let rocket = crate::custom(Config::figment());
360-
let _result = crate::local::blocking::Client::tracked(rocket);
358+
crate::local::blocking::Client::tracked(rocket).expect_err("boop secret key");
361359
Ok(())
362360
});
363361
}

0 commit comments

Comments
 (0)