Skip to content

Commit

Permalink
wip: convert more log messages to traces
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed May 11, 2024
1 parent aeb63bc commit ed77060
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
20 changes: 10 additions & 10 deletions core/lib/src/fs/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ impl FileServer {
/// ```
#[track_caller]
pub fn new<P: AsRef<Path>>(path: P, options: Options) -> Self {
use crate::yansi::Paint;

let path = path.as_ref();
if !options.contains(Options::Missing) {
if !options.contains(Options::IndexFile) && !path.is_dir() {
let path = path.display();
error!("FileServer path '{}' is not a directory.", path.primary());
warn_!("Aborting early to prevent inevitable handler error.");
panic!("invalid directory: refusing to continue");
error!(path = %path.display(),
"FileServer path does not point to a directory.\n\
Aborting early to prevent inevitable handler runtime errors.");

panic!("invalid directory path: refusing to continue");
} else if !path.exists() {
let path = path.display();
error!("FileServer path '{}' is not a file.", path.primary());
warn_!("Aborting early to prevent inevitable handler error.");
panic!("invalid file: refusing to continue");
error!(path = %path.display(),
"FileServer path does not point to a file.\n\
Aborting early to prevent inevitable handler runtime errors.");

panic!("invalid file path: refusing to continue");
}
}

Expand Down
13 changes: 6 additions & 7 deletions core/lib/src/fs/temp_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,16 @@ impl<'r> FromData<'r> for Capped<TempFile<'_>> {
type Error = io::Error;

async fn from_data(req: &'r Request<'_>, data: Data<'r>) -> data::Outcome<'r, Self> {
use yansi::Paint;

let has_form = |ty: &ContentType| ty.is_form_data() || ty.is_form();
if req.content_type().map_or(false, has_form) {
let (tf, form) = ("TempFile<'_>".primary(), "Form<TempFile<'_>>".primary());
warn_!("Request contains a form that will not be processed.");
info_!("Bare `{}` data guard writes raw, unprocessed streams to disk.", tf);
info_!("Did you mean to use `{}` instead?", form);
warn!(request.content_type = req.content_type().map(display),
"Request contains a form that is not being processed.\n\
Bare `TempFile` data guard writes raw, unprocessed streams to disk\n\
Perhaps you meant to use `Form<TempFile<'_>>` instead?");
}

TempFile::from(req, data, None, req.content_type().cloned()).await
TempFile::from(req, data, None, req.content_type().cloned())
.await
.or_error(Status::BadRequest)
}
}
Expand Down
3 changes: 0 additions & 3 deletions core/lib/src/response/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ impl<'r> FromRequest<'r> for FlashMessage<'r> {
type Error = ();

async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
trace_!("Flash: attempting to retrieve message.");
req.cookies().get(FLASH_COOKIE_NAME).ok_or(()).and_then(|cookie| {
trace_!("Flash: retrieving message: {:?}", cookie);

// Parse the flash message.
let content = cookie.value();
let (len_str, kv) = match content.find(FLASH_COOKIE_DELIM) {
Expand Down
13 changes: 6 additions & 7 deletions core/lib/src/router/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,23 @@ fn paths_match(route: &Route, req: &Request<'_>) -> bool {
fn queries_match(route: &Route, req: &Request<'_>) -> bool {
trace!(
route.query = route.uri.query().map(display),
route.query.color = route.uri.metadata.query_color.map(debug),
request.query = req.uri().query().map(display),
);

if matches!(route.uri.metadata.query_color, None | Some(Color::Wild)) {
return true;
}

let route_query_fields = route.uri.metadata.static_query_fields.iter()
.map(|(k, v)| (k.as_str(), v.as_str()));

for route_seg in route_query_fields {
let route_query_fields = route.uri.metadata.static_query_fields.iter();
for (key, val) in route_query_fields {
if let Some(query) = req.uri().query() {
if !query.segments().any(|req_seg| req_seg == route_seg) {
trace_!("request {} missing static query {:?}", req, route_seg);
if !query.segments().any(|req_seg| req_seg == (key, val)) {
debug!(key, val, request.query = %query, "missing static query");
return false;
}
} else {
trace_!("query-less request {} missing static query {:?}", req, route_seg);
debug!(key, val, "missing static query (queryless request)");
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion core/lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type Result<T, E = crate::Error> = std::result::Result<T, E>;

impl Rocket<Orbit> {
#[tracing::instrument("request", skip_all, fields(
timestamp = time::OffsetDateTime::now_utc().unix_timestamp_nanos(),
method = %parts.method,
uri = %parts.uri,
autohandled
Expand Down
8 changes: 4 additions & 4 deletions core/lib/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::ops::Deref;
use std::any::type_name;

use ref_cast::RefCast;
use yansi::Paint;

use crate::{Phase, Rocket, Ignite, Sentinel};
use crate::request::{self, FromRequest, Request};
Expand Down Expand Up @@ -211,9 +210,10 @@ impl<'r, T: Send + Sync + 'static> FromRequest<'r> for &'r State<T> {
impl<T: Send + Sync + 'static> Sentinel for &State<T> {
fn abort(rocket: &Rocket<Ignite>) -> bool {
if rocket.state::<T>().is_none() {
let type_name = type_name::<T>();
error!("launching with unmanaged `{}` state.", type_name.primary().bold());
info_!("Using `State` requires managing it with `.manage()`.");
error!(type_name = type_name::<T>(),
"unmanaged state detected\n\
ensure type is being managed via `rocket.manage()`");

return true;
}

Expand Down

0 comments on commit ed77060

Please sign in to comment.