Repository: cristianoliveira/funzzy (language: rust)

Issue:
fix: when loading yaml without explicity string
eg
```yaml
- name: adds to git
  run_on_init: true
  run:
    - git add {{relative_filepath}}
    - git add -p
    - git fetch && git rebase origin/main
  change: 
    - .fzz/git-task # touch .fzz/git-task
    - **/* ## THIS
  ignore:
    - git/**/*
    - result
```


Discussion / hints:

Fix patch:
diff --git a/.watch.yaml b/.watch.yaml
index 0421991..95d5651 100644
--- a/.watch.yaml
+++ b/.watch.yaml
@@ -93,8 +93,6 @@
     - 'git add $(echo "{{filepath}}" | sed "s#$PWD/##")'
     - 'git add . -p'
     # - 'git commit'
-    - git fetch --all
-    - git rebase origin/master
   change: 
     - ".watch.yaml"
     - "README.md"
@@ -107,3 +105,10 @@
     - "examples/workdir/**"
     - "examples/reload-config-example.yml"
   run_on_init: true
+
+- name: after commit attempt to rebase
+  run: 
+    - git fetch --all
+    - git rebase origin/master
+  change: 
+    - ".git/COMMIT_EDITMSG"
diff --git a/Cargo.lock b/Cargo.lock
index 88a81cb..39ea70d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -703,9 +703,9 @@ dependencies = [
 
 [[package]]
 name = "yaml-rust"
-version = "0.4.1"
+version = "0.4.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fe0fad48adbecafa9588846b38af3f015ccaef0a79d92f9b2892dd310aa9f9e1"
+checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
 dependencies = [
  "linked-hash-map",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index c96d05b..e91bfa9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ docopt = "1"
 serde = "1.0" # if you're using `derive(Deserialize)`
 serde_derive = "1.0" # if you're using `derive(Deserialize)`
 notify = "4.0.0"
-yaml-rust = "0.4.1"
+yaml-rust = "0.4.5"
 glob="0.2.11"
 notify-debouncer-mini = "0.3.0"
 nix = "0.26.2"
diff --git a/examples/list-of-commands-per-task.yaml b/examples/list-of-commands-per-task.yaml
deleted file mode 100644
index 14e5f8f..0000000
--- a/examples/list-of-commands-per-task.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-- name: run a list of commands
-  run: ["echo first", "echo second", "echo complex | sed s/complex/third/g"]
-  change: "src/**"
-  run_on_init: true
diff --git a/src/rules.rs b/src/rules.rs
index cf719b7..e9ac21c 100644
--- a/src/rules.rs
+++ b/src/rules.rs
@@ -177,12 +177,37 @@ pub fn from_yaml(file_content: &str) -> Result<Vec<Rules>, String> {
     let items = match YamlLoader::load_from_str(file_content) {
         Ok(val) => val,
         Err(err) => {
-            return Err(format!("Found an invalid yaml format {}", err));
+            let lines: Vec<&str> = file_content.lines().collect();
+            let marker = err.marker();
+
+            let error_line = if marker.line() > lines.len() {
+                lines[lines.len() - 1]
+            } else {
+                lines[marker.line() - 1]
+            };
+
+            return Err(vec![
+                format!("Failed to load configuration reason: {}", err),
+                "".to_owned(),
+                format!("Error line:\n  {}", error_line.trim()),
+                "".to_owned(),
+                "Debugging:".to_owned(),
+                "  - Is the type correct?".to_owned(),
+                "  - Is there any missing closing quotes, brackets or braces?".to_owned(),
+            ]
+            .join("\n"));
         }
     };
 
     if items.len() == 0 {
-        return Err("There is no rule in the config file.".to_owned());
+        return Err(vec![
+            "The config file is invalid!",
+            "",
+            "Debugging:",
+            "  - Did you forget to run 'fzz init'?",
+            "  - Did you forget to add a rule?",
+        ]
+        .join("\n"));
     }
 
     match items[0] {
@@ -421,6 +446,22 @@ mod tests {
         assert_eq!(false, rule.ignore("tests/foo.rs"));
     }
 
+    #[test]
+    fn test_yaml_loader_returns_empty_for_invalid_content() {
+        let file_content = "
+        - name: this is valid
+          run: 'cargo tests'
+          change: '**/*'
+
+        - name: this is invalid
+          run: 'cargo tests'
+          change: **/*
+        ";
+
+        let content = YamlLoader::load_from_str(file_content);
+        assert!(content.is_err());
+    }
+
     #[test]
     fn it_loads_from_args() {
         let file_content = "
@@ -580,4 +621,51 @@ mod tests {
             rules[0].as_string()
         );
     }
+
+    #[test]
+    fn it_fails_for_invalid_watch_file_format() {
+        let file_content = "
+        - name: this is valid
+          run: 'cargo tests'
+          change: '**/*'
+
+        - name: this is invalid
+          run: 'cargo tests'
+          change: **/*
+        ";
+
+        let result = from_yaml(file_content);
+        assert!(result.is_err());
+        assert_eq!(
+            result.err().unwrap(),
+            vec![
+                "Failed to load configuration reason: while scanning an anchor or alias, did not find expected alphabetic or numeric character at line 8 column 19",
+                "",
+                "Error line:",
+                "  change: **/*",
+                "",
+                "Debugging:",
+                "  - Is the type correct?",
+                "  - Is there any missing closing quotes, brackets or braces?",
+            ]
+            .join("\n")
+        );
+
+        let empty_file = "
+        ";
+
+        let result = from_yaml(empty_file);
+        assert!(result.is_err());
+        assert_eq!(
+            result.err().unwrap(),
+            vec![
+                "The config file is invalid!",
+                "",
+                "Debugging:",
+                "  - Did you forget to run 'fzz init'?",
+                "  - Did you forget to add a rule?",
+            ]
+            .join("\n")
+        );
+    }
 }
diff --git a/src/watches.rs b/src/watches.rs
index c89d29d..f58b336 100644
--- a/src/watches.rs
+++ b/src/watches.rs
@@ -293,17 +293,17 @@ mod tests {
 
     #[test]
     fn it_returns_an_error_when_fail_to_load_config_file() {
-        assert!(rules::from_yaml(
-            &r#"
-        - name: run tests
-          run: [
-            "yarn test {{filepath}}", 
-            "echo '{{filepath}}' | sed -r 's\/.tsx/\/'" 
-          ]
-          change: 'src/**'
-        "#
-        )
-        .is_err());
+        // assert!(rules::from_yaml(
+        //     &r#"
+        // - name: run tests
+        //   run: [
+        //     "yarn test {{filepath}}",
+        //     "echo '{{filepath}}' | sed -r 's\/.tsx/\/'"
+        //   ]
+        //   change: 'src/**'
+        // "#
+        // )
+        // .is_err());
 
         assert!(rules::from_yaml(
             &r#"


Test patch: