Skip to content

Commit

Permalink
fix: improve directory creation error handling (#1765)
Browse files Browse the repository at this point in the history
* Update main.rs

* Update main.rs

* Update main.rs

* Update main.rs
  • Loading branch information
crStiv authored Jan 18, 2025
1 parent bab9807 commit ccb7a69
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ enum CEError {
path: String,
toml_error: toml::de::Error,
},
#[error("Failed to create directory for ecosystem file: {path:?}")]
DirectoryCreationError { path: String },
}

type EcosystemMap = HashMap<String, Ecosystem>;
Expand Down Expand Up @@ -455,9 +457,12 @@ fn write_ecosystem_to_toml(repo_root: &Path, eco: &Ecosystem) -> Result<()> {
}
}

if std::fs::create_dir_all(toml_file_path.parent().unwrap()).is_err() {
println!("Error Making dir: {:?}", toml_file_path);
if let Some(parent) = toml_file_path.parent() {
std::fs::create_dir_all(parent).map_err(|_| CEError::DirectoryCreationError {
path: parent.display().to_string(),
})?;
}

let mut file = OpenOptions::new()
.read(true)
.write(true)
Expand Down

0 comments on commit ccb7a69

Please sign in to comment.