You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Soft-fail if .env fails to load
This commit is contained in:
@ -105,11 +105,10 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
async fn try_main() -> anyhow::Result<()> {
|
async fn try_main() -> anyhow::Result<()> {
|
||||||
// Load environment variables from .env files
|
// Load environment variables from .env files
|
||||||
// We keep the path to log it afterwards
|
// We keep the path to log it afterwards
|
||||||
let dotenv_path: Option<PathBuf> = dotenv::dotenv()
|
let dotenv_path: Result<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
|
||||||
@ -134,8 +133,10 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// Now that logging is set up, we can log stuff, like if the .env file was
|
// Now that logging is set up, we can log stuff, like if the .env file was
|
||||||
// loaded or not
|
// loaded or not
|
||||||
if let Some(path) = dotenv_path {
|
match dotenv_path {
|
||||||
tracing::info!(?path, "Loaded environment variables from file");
|
Ok(Some(path)) => tracing::info!(?path, "Loaded environment variables from file"),
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => tracing::warn!(%err, "failed to load .env file"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the CLI arguments
|
// Parse the CLI arguments
|
||||||
|
Reference in New Issue
Block a user