Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub enum ServiceError {
)]
NoWriteAccess,
#[error("{0}")]
InvalidConfig(String),
#[error("{0}")]
FromString(String),
#[error("{0}")]
TransportError(#[from] TransportError),
Expand Down
12 changes: 7 additions & 5 deletions src/fs_service/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ pub struct FileSystemService {

impl FileSystemService {
pub fn try_new(allowed_directories: &[String]) -> ServiceResult<Self> {
let normalized_dirs: Vec<PathBuf> = allowed_directories
let normalized_dirs: ServiceResult<Vec<PathBuf>> = allowed_directories
.iter()
.map(fix_dockerhub_mcp_registry_gateway)
.map_while(|dir| {
.map(|dir| {
let expand_result = expand_home(dir.into());
if !expand_result.is_dir() {
panic!("{}", format!("Error: {dir} is not a directory"));
return Err(ServiceError::InvalidConfig(format!(
"Error: The path `{dir}` is not a valid directory. Please double-check your server configuration to ensure the directory exists and is accessible."
)));
}
Some(expand_result)
Ok(expand_result)
})
.collect();

Ok(Self {
allowed_path: RwLock::new(Arc::new(normalized_dirs)),
allowed_path: RwLock::new(Arc::new(normalized_dirs?)),
})
}

Expand Down
5 changes: 3 additions & 2 deletions tests/test_fs_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ async fn test_try_new_success() {
}

#[test]
#[should_panic(expected = "Error: /does/not/exist is not a directory")]
fn test_try_new_invalid_directory() {
let _ = FileSystemService::try_new(&["/does/not/exist".to_string()]);
let result = FileSystemService::try_new(&["/does/not/exist".to_string()]);
assert!(result.is_err());
assert!(matches!(result, Err(ServiceError::InvalidConfig(_))));
}

#[tokio::test]
Expand Down
Loading