Skip to content

Commit

Permalink
fix(sequencer_node): fallback env var (#1785)
Browse files Browse the repository at this point in the history
commit-id:c14b827c
  • Loading branch information
Itay-Tsabary-Starkware authored Nov 4, 2024
1 parent 5582997 commit f9843c4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/sequencer_node/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use crate::communication::{create_node_channels, create_node_clients, SequencerNodeClients};
use crate::components::create_node_components;
Expand All @@ -20,5 +20,10 @@ pub fn create_node_modules(
// TODO(Tsabary): consolidate with other get_absolute_path functions.
/// Returns the absolute path from the project root.
pub fn get_absolute_path(relative_path: &str) -> PathBuf {
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../..").join(relative_path)
let base_dir = env::var("CARGO_MANIFEST_DIR")
// Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`. Ascend two directories ("../..") to get to the project root.
.map(|dir| PathBuf::from(dir).join("../.."))
// If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory
.unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory"));
base_dir.join(relative_path)
}

0 comments on commit f9843c4

Please sign in to comment.