Prettier main panicking.

This commit is contained in:
2026-09-25 18:06:15 +02:00
parent 94a5acc394
commit f3f576d7df
3 changed files with 20 additions and 9 deletions
+12 -9
View File
@@ -1,5 +1,6 @@
use std::env;
use anyhow::Context;
use sqlx::postgres::PgPoolOptions;
use tokio::net::TcpListener;
@@ -9,34 +10,36 @@ mod routes;
#[tokio::main]
#[tracing::instrument]
async fn main() {
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let database_url = env::var("DATABASE_URL").context("DATABASE_URL must be set")?;
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
.expect("Failed to connect to database");
.context("Failed to connect to database")?;
sqlx::migrate!()
.run(&pool)
.await
.expect("Failed to run database migrations");
.context("Failed to run database migrations")?;
let host = env::var("HOST").expect("HOST must be set");
let port = env::var("PORT").expect("PORT must be set");
let host = env::var("HOST").context("HOST must be set")?;
let port = env::var("PORT").context("PORT must be set")?;
let addr = format!("{}:{}", host, port);
let listener = TcpListener::bind(&addr)
.await
.expect(&format!("Failed to bind to address: {}", addr));
.context(format!("Failed to bind to address: {}", addr))?;
tracing::info!("Starting server at {}:{}", host, port);
tracing::info!(%addr, "Starting server");
axum::serve(listener, routes::create_router(pool).into_make_service())
.await
.expect("Failed to start server");
.context("Server stopped unexpectedly")?;
Ok(())
}