Skip to content

Commit 3d7f887

Browse files
committed
wip: remove painting outside trace in core
1 parent 26254a4 commit 3d7f887

File tree

11 files changed

+14
-92
lines changed

11 files changed

+14
-92
lines changed

core/lib/src/catcher/catcher.rs

-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use crate::request::Request;
88
use crate::http::{Status, ContentType, uri};
99
use crate::catcher::{Handler, BoxFuture};
1010

11-
use yansi::Paint;
12-
1311
/// An error catching route.
1412
///
1513
/// Catchers are routes that run when errors are produced by the application.
@@ -342,21 +340,6 @@ impl From<StaticInfo> for Catcher {
342340
}
343341
}
344342

345-
impl fmt::Display for Catcher {
346-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
347-
if let Some(ref n) = self.name {
348-
write!(f, "{}{}{} ", "(".cyan(), n.primary(), ")".cyan())?;
349-
}
350-
351-
write!(f, "{} ", self.base.path().green())?;
352-
353-
match self.code {
354-
Some(code) => write!(f, "{}", code.blue()),
355-
None => write!(f, "{}", "default".blue()),
356-
}
357-
}
358-
}
359-
360343
impl fmt::Debug for Catcher {
361344
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
362345
f.debug_struct("Catcher")

core/lib/src/response/debug.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::request::Request;
22
use crate::response::{self, Responder};
33
use crate::http::Status;
44

5-
use yansi::Paint;
6-
75
/// Debug prints the internal value before forwarding to the 500 error catcher.
86
///
97
/// This value exists primarily to allow handler return types that would not
@@ -78,16 +76,16 @@ impl<E> From<E> for Debug<E> {
7876

7977
impl<'r, E: std::fmt::Debug> Responder<'r, 'static> for Debug<E> {
8078
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
81-
warn_!("Debug: {:?}", self.0.primary());
82-
warn_!("Debug always responds with {}.", Status::InternalServerError.primary());
79+
let type_name = std::any::type_name::<E>();
80+
info!(type_name, value = ?self.0, "debug response (500)");
8381
Err(Status::InternalServerError)
8482
}
8583
}
8684

8785
/// Prints a warning with the error and forwards to the `500` error catcher.
8886
impl<'r> Responder<'r, 'static> for std::io::Error {
8987
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
90-
warn_!("I/O Error: {:?}", self.primary());
88+
warn!("i/o error response: {self}");
9189
Err(Status::InternalServerError)
9290
}
9391
}

core/lib/src/rocket.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::sync::Arc;
44
use std::time::Duration;
55
use std::any::Any;
66
use std::future::Future;
7+
use std::panic::Location;
78

8-
use yansi::Paint;
99
use either::Either;
1010
use figment::{Figment, Provider};
1111
use futures::TryFutureExt;
@@ -21,7 +21,6 @@ use crate::phase::{Stateful, StateRef, State};
2121
use crate::http::uri::Origin;
2222
use crate::http::ext::IntoOwned;
2323
use crate::error::{Error, ErrorKind};
24-
// use crate::log::PaintExt;
2524

2625
/// The application server itself.
2726
///
@@ -248,20 +247,18 @@ impl Rocket<Build> {
248247
B::Error: fmt::Display,
249248
M: Fn(&Origin<'a>, T) -> T,
250249
F: Fn(&mut Self, T),
251-
T: Clone + fmt::Display,
250+
T: Clone + Traceable,
252251
{
253252
let mut base = match base.clone().try_into() {
254253
Ok(origin) => origin.into_owned(),
255254
Err(e) => {
256-
error!("invalid {} base: {}", kind, Paint::white(&base));
257-
error_!("{}", e);
258-
info_!("{} {}", "in".primary(), std::panic::Location::caller());
255+
error!(%base, location = %Location::caller(), "invalid {kind} base uri: {e}");
259256
panic!("aborting due to {} base error", kind);
260257
}
261258
};
262259

263260
if base.query().is_some() {
264-
warn!("query in {} base '{}' is ignored", kind, Paint::white(&base));
261+
warn!(%base, location = %Location::caller(), "query in {kind} base is ignored");
265262
base.clear_query();
266263
}
267264

core/lib/src/route/route.rs

-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::fmt;
22
use std::borrow::Cow;
33

4-
use yansi::Paint;
5-
64
use crate::http::{uri, Method, MediaType};
75
use crate::route::{Handler, RouteUri, BoxFuture};
86
use crate::sentinel::Sentry;
@@ -343,27 +341,6 @@ impl Route {
343341
}
344342
}
345343

346-
impl fmt::Display for Route {
347-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
348-
if let Some(ref n) = self.name {
349-
write!(f, "{}{}{} ", "(".cyan(), n.primary(), ")".cyan())?;
350-
}
351-
352-
write!(f, "{} ", self.method.green())?;
353-
self.uri.color_fmt(f)?;
354-
355-
if self.rank > 1 {
356-
write!(f, " [{}]", self.rank.primary().bold())?;
357-
}
358-
359-
if let Some(ref format) = self.format {
360-
write!(f, " {}", format.yellow())?;
361-
}
362-
363-
Ok(())
364-
}
365-
}
366-
367344
impl fmt::Debug for Route {
368345
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
369346
f.debug_struct("Route")

core/lib/src/route/uri.rs

-16
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,6 @@ impl<'a> RouteUri<'a> {
238238
// We subtract `3` because `raw_path` is never `0`: 0b0100 = 4 - 3 = 1.
239239
-((raw_weight as isize) - 3)
240240
}
241-
242-
pub(crate) fn color_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
243-
use yansi::Paint;
244-
245-
let (path, base, unmounted) = (self.uri.path(), self.base(), self.unmounted().path());
246-
let unmounted_part = path.strip_prefix(base.as_str())
247-
.map(|raw| raw.as_str())
248-
.unwrap_or(unmounted.as_str());
249-
250-
write!(f, "{}{}", self.base().blue().underline(), unmounted_part.blue())?;
251-
if let Some(q) = self.unmounted().query() {
252-
write!(f, "{}{}", "?".yellow(), q.yellow())?;
253-
}
254-
255-
Ok(())
256-
}
257241
}
258242

259243
impl Metadata {

core/lib/src/router/collider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ mod tests {
226226
let (a, b) = (dummy_route($ranked, $m1, $p1), dummy_route($ranked, $m2, $p2));
227227
assert! {
228228
a.collides_with(&b),
229-
"\nroutes failed to collide:\n{} does not collide with {}\n", a, b
229+
"\nroutes failed to collide:\n{:?} does not collide with {:?}\n", a, b
230230
}
231231
};
232232
(ranked $($t:tt)+) => (assert_collision!(true, $($t)+));
@@ -239,7 +239,7 @@ mod tests {
239239
let (a, b) = (dummy_route($ranked, $m1, $p1), dummy_route($ranked, $m2, $p2));
240240
assert! {
241241
!a.collides_with(&b),
242-
"\nunexpected collision:\n{} collides with {}\n", a, b
242+
"\nunexpected collision:\n{:?} collides with {:?}\n", a, b
243243
}
244244
};
245245
(ranked $($t:tt)+) => (assert_no_collision!(true, $($t)+));

core/lib/src/router/router.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,10 @@ mod test {
580580
let req_status = Status::from_code(req.0).expect("valid status");
581581
let catcher = catcher(&router, req_status, req.1).expect("some catcher");
582582
assert_eq!(catcher.code, expected.0,
583-
"\nmatched {}, expected {:?} for req {:?}", catcher, expected, req);
583+
"\nmatched {:?}, expected {:?} for req {:?}", catcher, expected, req);
584584

585585
assert_eq!(catcher.base.path(), expected.1,
586-
"\nmatched {}, expected {:?} for req {:?}", catcher, expected, req);
586+
"\nmatched {:?}, expected {:?} for req {:?}", catcher, expected, req);
587587
}
588588
})
589589
}

core/lib/src/tls/resolver.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@ impl<T: Resolver> fairing::Fairing for Fairing<T> {
7373
}
7474

7575
async fn on_ignite(&self, rocket: Rocket<Build>) -> fairing::Result {
76-
use yansi::Paint;
77-
7876
let result = T::init(&rocket).await;
7977
match result {
8078
Ok(resolver) => Ok(rocket.manage(Arc::new(resolver) as Arc<dyn Resolver>)),
8179
Err(e) => {
82-
let name = std::any::type_name::<T>();
83-
error!("TLS resolver {} failed to initialize.", name.primary().bold());
84-
error_!("{e}");
80+
let type_name = std::any::type_name::<T>();
81+
error!(type_name, reason = %e, "TLS resolver failed to initialize");
8582
Err(rocket)
8683
}
8784
}

core/lib/src/trace/macros.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
pub trait PaintExt: Sized {
2-
fn emoji(self) -> yansi::Painted<Self>;
3-
}
4-
5-
impl PaintExt for &str {
6-
/// Paint::masked(), but hidden on Windows due to broken output. See #1122.
7-
fn emoji(self) -> yansi::Painted<Self> {
8-
#[cfg(windows)] { yansi::Paint::new("").mask() }
9-
#[cfg(not(windows))] { yansi::Paint::new(self).mask() }
10-
}
11-
}
12-
131
macro_rules! declare_macro {
142
($($name:ident $level:ident),* $(,)?) => (
153
$(declare_macro!([$] $name $level);)*

core/lib/src/trace/traceable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl Traceable for Route {
142142
format = self.format.as_ref().map(display),
143143
}
144144

145-
event! { Level::DEBUG, "route",
145+
event! { Level::DEBUG, "sentinels",
146146
route = self.name.as_ref().map(|n| &**n),
147147
sentinels = %Formatter(|f| {
148148
f.debug_set()

examples/hello/src/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use rocket::fairing::AdHoc;
2-
31
#[macro_use] extern crate rocket;
42

53
#[cfg(test)] mod tests;

0 commit comments

Comments
 (0)