You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Better error context on startup
This commit is contained in:
@ -108,12 +108,15 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
let dotenv_path: Option<PathBuf> = dotenv::dotenv()
|
let dotenv_path: Option<PathBuf> = dotenv::dotenv()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
// Display the error if it is something other than the .env file not existing
|
// Display the error if it is something other than the .env file not existing
|
||||||
.or_else(|e| if e.not_found() { Ok(None) } else { Err(e) })?;
|
.or_else(|e| if e.not_found() { Ok(None) } else { Err(e) })
|
||||||
|
.context("failed to load .env file")?;
|
||||||
|
|
||||||
// Setup logging
|
// Setup logging
|
||||||
// This writes logs to stderr
|
// This writes logs to stderr
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer().with_writer(std::io::stderr);
|
let fmt_layer = tracing_subscriber::fmt::layer().with_writer(std::io::stderr);
|
||||||
let filter_layer = EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?;
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
|
.or_else(|_| EnvFilter::try_new("info"))
|
||||||
|
.context("could not setup logging filter")?;
|
||||||
|
|
||||||
// Don't fill the telemetry layer for now, we want to configure it based on the
|
// Don't fill the telemetry layer for now, we want to configure it based on the
|
||||||
// app config, so we need to delay that a bit
|
// app config, so we need to delay that a bit
|
||||||
@ -144,7 +147,7 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
let telemetry_config: TelemetryConfig = opts.load_config().unwrap_or_default();
|
let telemetry_config: TelemetryConfig = opts.load_config().unwrap_or_default();
|
||||||
|
|
||||||
// Setup OpenTelemtry tracing and metrics
|
// Setup OpenTelemtry tracing and metrics
|
||||||
let tracer = telemetry::setup(&telemetry_config)?;
|
let tracer = telemetry::setup(&telemetry_config).context("failed to setup opentelemetry")?;
|
||||||
if let Some(tracer) = tracer {
|
if let Some(tracer) = tracer {
|
||||||
// Now we can swap out the actual opentelemetry tracing layer
|
// Now we can swap out the actual opentelemetry tracing layer
|
||||||
handle.reload(
|
handle.reload(
|
||||||
|
@ -215,8 +215,12 @@ impl ServerCommand {
|
|||||||
pub async fn run(&self, root: &RootCommand) -> anyhow::Result<()> {
|
pub async fn run(&self, root: &RootCommand) -> anyhow::Result<()> {
|
||||||
let config: RootConfig = root.load_config()?;
|
let config: RootConfig = root.load_config()?;
|
||||||
|
|
||||||
let addr: SocketAddr = config.http.address.parse()?;
|
let addr: SocketAddr = config
|
||||||
let listener = TcpListener::bind(addr)?;
|
.http
|
||||||
|
.address
|
||||||
|
.parse()
|
||||||
|
.context("could not parse listener address")?;
|
||||||
|
let listener = TcpListener::bind(addr).context("could not bind address")?;
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
let pool = config.database.connect().await?;
|
let pool = config.database.connect().await?;
|
||||||
|
Reference in New Issue
Block a user