Repository: sharkdp/bat (language: rust)

Issue:
ThemeSet always empty
**Environment**

bat 0.11.0 on macOS using the default config path

**Description**

I tried to add a custom theme using the following directory structure:
```console
$ tree /Users/me/.config/bat/themes
/Users/me/.config/bat/themes
└── solarized-dark
    └── solarized-dark.tmTheme
```

but `bat cache -b` does not find my theme:

```console
$ bat cache --blank -b
No themes were found in '/Users/me/.config/bat/themes', using the default set
No syntaxes were found in '/Users/me/.config/bat/syntaxes', using the default set.
Writing theme set to /Users/me/.cache/bat/themes.bin ... okay
Writing syntax set to /Users/me/.cache/bat/syntaxes.bin ... okay
```

I quickly checked the following code, and from my understanding of the [`ThemeSet::add_from_folder()`](https://docs.rs/syntect/3.2.0/src/syntect/highlighting/theme_set.rs.html#53-64) method (not familiar with Rust, bear with me) the directory tree shown above should be correct https://github.com/sharkdp/bat/blob/c9d7e3652bb0be4becdecfd8d2e7d4e795071c83/src/assets.rs#L42-L48


Discussion / hints:
My mistake, the `tmTheme` file was simply wrongly formatted.
Thanks @antoineco I just ran into this - it appears that if one theme in the themes/ dir is badly formatted it defaults to loading none of them. Maybe this could be improved to at least show a better error (badly formatted theme found) and even better to load the well formatted themes. 
Here is how to trigger the code that runs if a theme has invalid syntax:

    % mkdir -p ~/.config/bat/themes/invalid-theme
    % echo invalid > ~/.config/bat/themes/invalid-theme/invalid-theme.tmTheme
    % bat cache --build
    No themes were found in '/Users/martinhobby/.config/bat/themes', using the default set
    [...]

The `syntect` code for `ThemeSet.add_from_folder()` looks (simplified) like this:

```
        for p in &paths {
            let theme = Self::get_theme(p)?;
            [...]
        }

        Ok(())
```

so it looks to me like not all themes fails to load because of one faulty theme, it is only the themes that comes _after_ (in the `WalkDir::new` sense) the faulty theme that fails to load.

The error returned from `syntect` actually says what is wrong, it's just that we don't show it. I propose that we show it, so that instead of

```
No themes were found in '/Users/martinhobby/.config/bat/themes', using the default set
```

the error message looks like this:

```
Failed to load one or more themes from '/Users/martinhobby/.config/bat/themes' (reason: 'Invalid syntax theme settings')
```

Unfortunately `syntect` does not include information about _what_ theme that has problems, but I'd say it is still a big improvement to say that the problem _is_. If this is not enough, `syntect` need to change/amend their API.

Do you think the proposed new error message would be enough to figure out what what wrong, @antoineco @TC-mSundaram ?

(I will soon create a PR with the code for my proposal.)


Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e0fb4ae274..43ef84934d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
 - Only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
 - Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
 - VimL syntax highlighting fix, see #1450 (@esensar)
+- Print an 'Invalid syntax theme settings' error message if a custom theme is broken, see #614 (@Enselic)
 
 ## Other
 
diff --git a/src/assets.rs b/src/assets.rs
index 5e0c064439..55b4941eca 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -38,9 +38,16 @@ impl HighlightingAssets {
         };
 
         let theme_dir = source_dir.join("themes");
-
-        let res = theme_set.add_from_folder(&theme_dir);
-        if res.is_err() {
+        if theme_dir.exists() {
+            let res = theme_set.add_from_folder(&theme_dir);
+            if let Err(err) = res {
+                println!(
+                    "Failed to load one or more themes from '{}' (reason: '{}')",
+                    theme_dir.to_string_lossy(),
+                    err,
+                );
+            }
+        } else {
             println!(
                 "No themes were found in '{}', using the default set",
                 theme_dir.to_string_lossy()


Test patch: