diff --git a/crates/infra_utils/src/path.rs b/crates/infra_utils/src/path.rs index cfa2444a24..f3ceeb0802 100644 --- a/crates/infra_utils/src/path.rs +++ b/crates/infra_utils/src/path.rs @@ -1,28 +1,16 @@ -use std::env; use std::path::{Path, PathBuf}; use std::sync::LazyLock; - -use thiserror::Error; +use std::{env, fs}; #[cfg(test)] #[path = "path_test.rs"] mod path_test; -#[derive(Debug, Error)] -pub enum PathResolutionError { - // TODO(Arni): Handle manifest dir not exist here? - #[error("No file exists at '{path}'")] - PathDoesNotExist { path: PathBuf }, - /// This error is raised when file existence can be neither confirmed nor denied. See - /// [`std::path::Path::try_exists`] for more information. - #[error(transparent)] - IoError(#[from] std::io::Error), -} - // TODO(tsabary): wrap path-related env::* invocations in the repo as utility functions static PATH_TO_CARGO_MANIFEST_DIR: LazyLock> = LazyLock::new(|| env::var("CARGO_MANIFEST_DIR").ok().map(|dir| Path::new(&dir).into())); +// TODO(Tsabary): should not be public. Use a getter instead. pub fn cargo_manifest_dir() -> Option { PATH_TO_CARGO_MANIFEST_DIR.clone() } @@ -34,16 +22,13 @@ pub fn cargo_manifest_dir() -> Option { /// * `relative_path` - A string slice representing the relative path from the project root. /// /// # Returns -/// * An absolute `PathBuf` representing the resolved path starting from the project root. -pub fn resolve_project_relative_path(relative_path: &str) -> Result { +/// * A `PathBuf` representing the resolved path starting from the project root. +pub fn resolve_project_relative_path(relative_path: &str) -> Result { let base_dir = path_of_project_root(); - let path = base_dir.join(relative_path); - if !path.try_exists()? { - return Err(PathResolutionError::PathDoesNotExist { path }); - } + let absolute_path = fs::canonicalize(path)?; - Ok(path) + Ok(absolute_path) } fn path_of_project_root() -> PathBuf { diff --git a/crates/infra_utils/src/path_test.rs b/crates/infra_utils/src/path_test.rs index 88d7f5ff23..8133007262 100644 --- a/crates/infra_utils/src/path_test.rs +++ b/crates/infra_utils/src/path_test.rs @@ -1,6 +1,5 @@ -use crate::path::{path_of_project_root, resolve_project_relative_path, PathResolutionError}; +use crate::path::{path_of_project_root, resolve_project_relative_path}; -// TODO: Add a test for PathResolutionError::IoError. #[test] fn resolve_project_relative_path_on_non_existent_path() { let relative_path = "does_not_exist.txt"; @@ -8,11 +7,7 @@ fn resolve_project_relative_path_on_non_existent_path() { assert!(!expected_path.exists()); let result = resolve_project_relative_path(relative_path); - if let Err(PathResolutionError::PathDoesNotExist { path }) = result { - assert_eq!(path, expected_path); - } else { - panic!("Expected PathDoesNotExist error, got {:?}", result); - } + assert!(result.is_err(), "Expected an non-existent path error, got {:?}", result); } #[test] diff --git a/crates/papyrus_config/src/lib.rs b/crates/papyrus_config/src/lib.rs index 77e4106f16..7a383cef54 100644 --- a/crates/papyrus_config/src/lib.rs +++ b/crates/papyrus_config/src/lib.rs @@ -49,7 +49,6 @@ use clap::parser::MatchesError; use dumping::REQUIRED_PARAM_DESCRIPTION_PREFIX; -use infra_utils::path::PathResolutionError; use serde::{Deserialize, Serialize}; use serde_json::Value; use validator::ValidationError; @@ -180,8 +179,6 @@ pub enum ConfigError { #[error(transparent)] CommandMatches(#[from] MatchesError), #[error(transparent)] - GetPathError(#[from] PathResolutionError), - #[error(transparent)] IOError(#[from] std::io::Error), // TODO(Eitan): Improve error message #[error("Insert a new param is not allowed: {param_path}.")]