Skip to content

Commit 821c84f

Browse files
authored
BM-249: Handle .env file not found gracefully (github#72)
1 parent 4db0e5b commit 821c84f

File tree

2 files changed

+14
-3
lines changed
  • crates/boundless-market/src/bin
  • examples/counter/apps/src

2 files changed

+14
-3
lines changed

crates/boundless-market/src/bin/cli.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@ async fn main() -> Result<()> {
161161
tracing_subscriber::fmt()
162162
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
163163
.init();
164-
dotenvy::dotenv()?;
164+
165+
match dotenvy::dotenv() {
166+
Ok(path) => tracing::debug!("Loaded environment variables from {:?}", path),
167+
Err(e) if e.not_found() => tracing::debug!("No .env file found"),
168+
Err(e) => bail!("failed to load .env file: {}", e),
169+
}
170+
165171
let args = MainArgs::try_parse()?;
166172

167173
let caller = args.private_key.address();

examples/counter/apps/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use alloy::{
1010
signers::local::PrivateKeySigner,
1111
sol_types::SolCall,
1212
};
13-
use anyhow::{Context, Result};
13+
use anyhow::{bail, Context, Result};
1414
use boundless_market::{
1515
contracts::{Input, Offer, Predicate, ProvingRequest, Requirements},
1616
sdk::client::Client,
@@ -61,7 +61,12 @@ async fn main() -> Result<()> {
6161
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
6262
.init();
6363

64-
dotenvy::dotenv()?;
64+
match dotenvy::dotenv() {
65+
Ok(path) => tracing::debug!("Loaded environment variables from {:?}", path),
66+
Err(e) if e.not_found() => tracing::debug!("No .env file found"),
67+
Err(e) => bail!("failed to load .env file: {}", e),
68+
}
69+
6570
let args = Args::parse();
6671

6772
// NOTE: Using a separate `run` function to facilitate testing below.

0 commit comments

Comments
 (0)