From be5fd8e2714cb860551d36a44091e31dbfc36dfe Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 26 Aug 2021 11:14:49 +0200 Subject: [PATCH] Better handle .env file loading error Previously it would crash if the file did not exist --- matrix-authentication-service/src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/matrix-authentication-service/src/main.rs b/matrix-authentication-service/src/main.rs index 068ccc598..e5922e194 100644 --- a/matrix-authentication-service/src/main.rs +++ b/matrix-authentication-service/src/main.rs @@ -35,7 +35,12 @@ use self::cli::RootCommand; #[tokio::main] async fn main() -> anyhow::Result<()> { // Load environment variables from .env files - dotenv::dotenv()?; + if let Err(e) = dotenv::dotenv() { + // Display the error if it is something other than the .env file not existing + if !e.not_found() { + return Err(e).context("could not load .env file"); + } + } // Setup logging & tracing let fmt_layer = tracing_subscriber::fmt::layer();