refactor: panic on an unsuccessful .env load on a database connection

This commit is contained in:
Matouš Volf 2024-09-10 16:13:29 +02:00
parent 1c6d735d52
commit 587ed9e2d7

View File

@ -4,9 +4,9 @@ use dotenvy::dotenv;
use std::env; use std::env;
pub(crate) fn establish_database_connection() -> ConnectionResult<PgConnection> { pub(crate) fn establish_database_connection() -> ConnectionResult<PgConnection> {
dotenv().ok(); dotenv().expect("Could not load environment variables.");
let database_url = let database_url =
env::var("DATABASE_URL").expect("The environment variable DATABASE_URL must be set."); env::var("DATABASE_URL").expect("The environment variable DATABASE_URL has to be set.");
PgConnection::establish(&database_url) PgConnection::establish(&database_url)
} }