Skip to content

Commit 9fa75a5

Browse files
ilitterifmoletta
authored andcommitted
fix(l2): create .env if needed in contract deployer bin (#2742)
**Motivation** If you init the stack in a fresh-cloned repo, the deployer bin will panic if you do not have a `.env` file already created. **Description** Creates a `.env` file if it doesn't exist at the moment of writing.
1 parent 56c196b commit 9fa75a5

File tree

1 file changed

+14
-2
lines changed
  • crates/l2/contracts/bin/deployer

1 file changed

+14
-2
lines changed

crates/l2/contracts/bin/deployer/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
fs::{read_to_string, OpenOptions},
2+
fs::{read_to_string, File, OpenOptions},
33
io::{BufWriter, Write},
44
path::PathBuf,
55
process::{Command, ExitStatus},
@@ -439,10 +439,22 @@ fn write_contract_addresses_to_env(
439439
risc0_verifier_address: Address,
440440
env_file_path: Option<PathBuf>,
441441
) -> Result<(), DeployerError> {
442+
let env_file_path =
443+
env_file_path.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.env")); // ethrex/crates/l2/.env
444+
445+
if !env_file_path.exists() {
446+
File::create(&env_file_path).map_err(|err| {
447+
DeployerError::InternalError(format!(
448+
"Failed to create .env file at {}: {err}",
449+
env_file_path.display()
450+
))
451+
})?;
452+
}
453+
442454
let env_file = OpenOptions::new()
443455
.write(true)
444456
.truncate(true)
445-
.open(env_file_path.unwrap_or(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.env")))?; // ethrex/crates/l2/.env
457+
.open(env_file_path)?; // ethrex/crates/l2/.env
446458
let mut writer = BufWriter::new(env_file);
447459
writeln!(
448460
writer,

0 commit comments

Comments
 (0)