diff --git a/foods.db-journal b/foods.db-journal new file mode 100644 index 0000000..466cfbb Binary files /dev/null and b/foods.db-journal differ diff --git a/src/main.rs b/src/main.rs index 8fcea50..b93ad4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use axum::{ use rusqlite::Connection; use tower_http::trace::TraceLayer; use tower_request_id::{RequestId, RequestIdLayer}; -use tracing::{debug, info, info_span}; +use tracing::{debug, error, info, info_span}; use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _}; #[derive(Template)] @@ -40,7 +40,7 @@ struct Food { } #[tokio::main] -async fn main() { +async fn main() -> Result<(), std::io::Error> { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { @@ -57,8 +57,12 @@ async fn main() { .init(); let db_connecion_str = "./foods.db".to_string(); - let conn = Connection::open(db_connecion_str).unwrap(); - conn.execute(include_str!("create_tables.sql"), ()).unwrap(); + debug!(db_connecion_str, "opening database"); + let conn = Connection::open(db_connecion_str).expect("failed to open database"); + if let Err(e) = conn.execute(include_str!("create_tables.sql"), ()) { + error!(?e, "failed to create tables"); + panic!("failed to create tables: {:#?}", e); + } let conn = Arc::new(Mutex::new(conn)); let app = Router::new() @@ -88,9 +92,17 @@ async fn main() { .layer(RequestIdLayer) .with_state(conn); - let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap(); - info!("listening on {}", listener.local_addr().unwrap()); - axum::serve(listener, app).await.unwrap(); + let address = "0.0.0.0:3001"; + let listener = tokio::net::TcpListener::bind(address) + .await + .expect("failed to bind to address"); + info!( + "listening on {}", + listener + .local_addr() + .expect("failed to get local listening address") + ); + axum::serve(listener, app).await } fn get_foods(conn: &Arc>) -> Vec {