Repository: comtrya/comtrya (language: rust)

Issue:
Bug: multiple manifests with same name will fail
**Description**
I've used the same manifest name (`main.yaml`) in subdirectories and it will fail when adding it to the manifests list.
https://github.com/comtrya/comtrya/blob/main/lib/src/manifests/load.rs#L111

**Steps to reproduce**
Create a new comtrya directory and re-use the same manifest name multiple times.
Or use my private configuration here: https://github.com/thebino/dotfiles

**Expected behaviour**
comtrya should succeed without any error

**Environment**
- OS: Mac Big Sur
- Version: `0.8.7`

**Additional information**
Add more context which didn't fit in the fields above.



Discussion / hints:
Hey :)

The name is not a problem. Some of your `main.yaml` files are not valid YAML. The problem does not reach the CLI. We need to work on better error reporting here 👍 

Fix patch:
diff --git a/lib/src/manifests/load.rs b/lib/src/manifests/load.rs
index ce5239ab..cba86862 100644
--- a/lib/src/manifests/load.rs
+++ b/lib/src/manifests/load.rs
@@ -87,9 +87,14 @@ pub fn load(manifest_path: PathBuf, contexts: &Contexts) -> HashMap<String, Mani
                     }
                 };
 
-                let manifest: Option<Manifest> = match entry.extension().and_then(OsStr::to_str) {
-                    Some("yaml") | Some("yml") => serde_yaml::from_str(template.deref()).ok(),
-                    Some("toml") => toml::from_str(template.deref()).ok(),
+                let manifest: anyhow::Result<Manifest> = match entry
+                    .extension()
+                    .and_then(OsStr::to_str)
+                {
+                    Some("yaml") | Some("yml") => {
+                        serde_yaml::from_str(template.deref()).map_err(anyhow::Error::from)
+                    }
+                    Some("toml") => toml::from_str(template.deref()).map_err(anyhow::Error::from),
                     _ => {
                         error!("Unrecognized file extension for manifest");
                         span.exit();
@@ -98,17 +103,23 @@ pub fn load(manifest_path: PathBuf, contexts: &Contexts) -> HashMap<String, Mani
                     }
                 };
 
-                if let Some(mut manifest) = manifest {
-                    let name = get_manifest_name(&manifest_path, &entry)
-                        .expect("Failed to get manifest name");
+                match manifest {
+                    Ok(mut manifest) => {
+                        let name = get_manifest_name(&manifest_path, &entry)
+                            .expect("Failed to get manifest name");
 
-                    manifest.root_dir = entry.parent().map(|parent| parent.to_path_buf());
+                        manifest.root_dir = entry.parent().map(|parent| parent.to_path_buf());
 
-                    manifest.name = Some(name.clone());
+                        manifest.name = Some(name.clone());
 
-                    manifests.insert(name, manifest);
-                } else {
-                    error!("Unrecognized file extension for manifest");
+                        manifests.insert(name, manifest);
+                    }
+                    Err(err) => {
+                        let manifest_name =
+                            get_manifest_name(&manifest_path, &entry).unwrap_or_default();
+
+                        error!("Manifest '{manifest_name}' in file with path '{}' cannot be parsed. Reason: {err}", &entry.display());
+                    }
                 }
 
                 span.exit();


Test patch: