fix config check running too late, add tower panic catcher(?)

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-20 23:01:41 -04:00 committed by June
parent 94dfe26707
commit aaba7342b5
5 changed files with 12 additions and 7 deletions

1
Cargo.lock generated
View file

@ -3437,6 +3437,7 @@ dependencies = [
"bitflags 2.5.0",
"bytes",
"futures-core",
"futures-util",
"http",
"http-body",
"http-body-util",

View file

@ -105,7 +105,7 @@ features = ["util"]
[dependencies.tower-http]
version = "0.5.2"
features = ["add-extension", "cors", "sensitive-headers", "trace", "util"]
features = ["add-extension", "cors", "sensitive-headers", "trace", "util", "catch-panic"]
[dependencies.hyper]
version = "1.3.1"

View file

@ -5,7 +5,7 @@ use tracing::{debug, error, info, warn};
use crate::{utils::error::Error, Config};
pub fn check(config: &Config) -> Result<(), Error> {
pub(super) fn check(config: &Config) -> Result<(), Error> {
config.warn_deprecated();
config.warn_unknown_key();

View file

@ -22,10 +22,10 @@ use serde::{de::IgnoredAny, Deserialize};
use tracing::{debug, error, warn};
use url::Url;
use self::proxy::ProxyConfig;
use self::{check::check, proxy::ProxyConfig};
use crate::utils::error::Error;
mod check;
pub(crate) mod check;
mod proxy;
#[derive(Deserialize, Clone, Debug)]
@ -371,8 +371,6 @@ impl Config {
Ok(config) => config,
};
check::check(&config)?;
// don't start if we're listening on both UNIX sockets and TCP at same time
if config.is_dual_listening(&raw_config) {
return Err(Error::bad_config("dual listening on UNIX and TCP sockets not allowed."));
@ -452,6 +450,8 @@ impl Config {
.collect::<Vec<_>>(),
}
}
pub fn check(&self) -> Result<(), Error> { check(self) }
}
impl fmt::Display for Config {

View file

@ -30,6 +30,7 @@ use tokio::{
};
use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
cors::{self, CorsLayer},
trace::{DefaultOnFailure, TraceLayer},
ServiceBuilderExt as _,
@ -76,7 +77,7 @@ async fn async_main(server: &Server) -> Result<(), Error> {
if let Err(error) = run(server).await {
error!("Critical error running server: {error}");
return Err(Error::Error(format!("{error}")));
};
}
if let Err(error) = stop(server).await {
error!("Critical error stopping server: {error}");
@ -274,6 +275,7 @@ async fn build(server: &Server) -> io::Result<axum::routing::IntoMakeService<Rou
let middlewares = base_middlewares
.sensitive_headers([header::AUTHORIZATION])
.sensitive_request_headers([x_forwarded_for].into())
.layer(CatchPanicLayer::new())
.layer(axum::middleware::from_fn(request_spawn))
.layer(
TraceLayer::new_for_http()
@ -438,6 +440,8 @@ fn init(args: clap::Args) -> Result<Server, Error> {
tracing_reload_handle = init_tracing_sub(&config);
};
config.check()?;
info!(
server_name = ?config.server_name,
database_path = ?config.database_path,