feat: remove from fspath conversion for storagelockerr (#14291)

This commit is contained in:
Steven
2025-02-07 02:51:03 -06:00
committed by GitHub
parent 2933ec7298
commit dc0488cf75
4 changed files with 7 additions and 9 deletions

1
Cargo.lock generated
View File

@ -9334,7 +9334,6 @@ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",
"derive_more", "derive_more",
"reth-fs-util",
"reth-primitives-traits", "reth-primitives-traits",
"reth-prune-types", "reth-prune-types",
"reth-static-file-types", "reth-static-file-types",

View File

@ -86,7 +86,7 @@ impl StorageLockInner {
fn new(file_path: PathBuf) -> Result<Self, StorageLockError> { fn new(file_path: PathBuf) -> Result<Self, StorageLockError> {
// Create the directory if it doesn't exist // Create the directory if it doesn't exist
if let Some(parent) = file_path.parent() { if let Some(parent) = file_path.parent() {
reth_fs_util::create_dir_all(parent)?; reth_fs_util::create_dir_all(parent).map_err(StorageLockError::other)?;
} }
// Write this process unique identifier (pid & start_time) to file // Write this process unique identifier (pid & start_time) to file
@ -148,7 +148,8 @@ impl ProcessUID {
/// Writes `pid` and `start_time` to a file. /// Writes `pid` and `start_time` to a file.
fn write(&self, path: &Path) -> Result<(), StorageLockError> { fn write(&self, path: &Path) -> Result<(), StorageLockError> {
Ok(reth_fs_util::write(path, format!("{}\n{}", self.pid, self.start_time))?) reth_fs_util::write(path, format!("{}\n{}", self.pid, self.start_time))
.map_err(StorageLockError::other)
} }
} }

View File

@ -12,7 +12,6 @@ workspace = true
[dependencies] [dependencies]
# reth # reth
reth-fs-util.workspace = true
reth-primitives-traits.workspace = true reth-primitives-traits.workspace = true
reth-prune-types.workspace = true reth-prune-types.workspace = true
reth-static-file-types.workspace = true reth-static-file-types.workspace = true

View File

@ -1,5 +1,4 @@
use alloc::string::{String, ToString}; use alloc::string::{String, ToString};
use reth_fs_util::FsPathError;
/// Storage lock error. /// Storage lock error.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
@ -12,9 +11,9 @@ pub enum StorageLockError {
Other(String), Other(String),
} }
/// TODO: turn into variant once `ProviderError` impl StorageLockError {
impl From<FsPathError> for StorageLockError { /// Converts any error into the `Other` variant of `StorageLockError`.
fn from(error: FsPathError) -> Self { pub fn other<E: core::error::Error>(err: E) -> Self {
Self::Other(error.to_string()) Self::Other(err.to_string())
} }
} }