on master help sign in
Better error handling
commitc826c2a43857d73b1cadc35d0fff5bc0951be70a authorsharkdp <davidpeter@web.de> dateWed 16 May 2018, 22:23 (8 years ago) parent9aa97b6
1 file changed+14−29
src/assets.rs+14−29
src/assets.rs+14−29
@@ -26,16 +26,8 @@ impl HighlightingAssets {
2626 let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
2727
2828 let theme_dir = source_dir.join("themes");
29− let theme_set = ThemeSet::load_from_folder(&theme_dir).map_err(|_| {
30− io::Error::new(
31− io::ErrorKind::Other,
32− format!(
33− "Could not load themes from '{}'",
34− theme_dir.to_string_lossy()
35− ),
36− )
37− })?;
38−
29+ let theme_set =
30+ ThemeSet::load_from_folder(&theme_dir).chain_err(|| "Could not load themes from '{}'")?;
3931 let mut syntax_set = SyntaxSet::new();
4032 let syntax_dir = source_dir.join("syntaxes");
4133 if !syntax_dir.exists() {
@@ -61,9 +53,8 @@ impl HighlightingAssets {
6153 syntax_set_path().to_string_lossy()
6254 )
6355 })?;
64− let mut syntax_set: SyntaxSet = from_reader(syntax_set_file).map_err(|_| {
65− io::Error::new(io::ErrorKind::Other, "Could not parse cached syntax set")
66− })?;
56+ let mut syntax_set: SyntaxSet =
57+ from_reader(syntax_set_file).chain_err(|| "Could not parse cached syntax set")?;
6758 syntax_set.link_syntaxes();
6859
6960 let theme_set_file = File::open(&theme_set_path).chain_err(|| {
@@ -72,8 +63,8 @@ impl HighlightingAssets {
7263 theme_set_path.to_string_lossy()
7364 )
7465 })?;
75− let theme_set: ThemeSet = from_reader(theme_set_file)
76− .map_err(|_| io::Error::new(io::ErrorKind::Other, "Could not parse cached theme set"))?;
66+ let theme_set: ThemeSet =
67+ from_reader(theme_set_file).chain_err(|| "Could not parse cached theme set")?;
7768
7869 Ok(HighlightingAssets {
7970 syntax_set,
@@ -102,13 +93,10 @@ impl HighlightingAssets {
10293 "Writing theme set to {} ... ",
10394 theme_set_path.to_string_lossy()
10495 );
105− dump_to_file(&self.theme_set, &theme_set_path).map_err(|_| {
106− io::Error::new(
107− io::ErrorKind::Other,
108− format!(
109− "Could not save theme set to {}",
110− theme_set_path.to_string_lossy()
111− ),
96+ dump_to_file(&self.theme_set, &theme_set_path).chain_err(|| {
97+ format!(
98+ "Could not save theme set to {}",
99+ theme_set_path.to_string_lossy()
112100 )
113101 })?;
114102 println!("okay");
@@ -117,13 +105,10 @@ impl HighlightingAssets {
117105 "Writing syntax set to {} ... ",
118106 syntax_set_path.to_string_lossy()
119107 );
120− dump_to_file(&self.syntax_set, &syntax_set_path).map_err(|_| {
121− io::Error::new(
122− io::ErrorKind::Other,
123− format!(
124− "Could not save syntax set to {}",
125− syntax_set_path.to_string_lossy()
126− ),
108+ dump_to_file(&self.syntax_set, &syntax_set_path).chain_err(|| {
109+ format!(
110+ "Could not save syntax set to {}",
111+ syntax_set_path.to_string_lossy()
127112 )
128113 })?;
129114 println!("okay");