]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #2069 from SingingTree/log_path_str_if_after_file_errors
authorNick Cameron <nrc@ncameron.org>
Thu, 26 Oct 2017 20:09:43 +0000 (01:39 +0530)
committerGitHub <noreply@github.com>
Thu, 26 Oct 2017 20:09:43 +0000 (01:39 +0530)
Return a more verbose error when formatting a file fails

1  2 
src/lib.rs

diff --cc src/lib.rs
index f9b96d59aca7f73a258c34a20df783db29b179ca,7834dfd26874e535772c00dfe4ae41c6b9f0da87..c8045747bfb9cbcacba6c08877d24acea62191e4
@@@ -319,17 -319,20 +319,24 @@@ wher
          let filemap = visitor.codemap.lookup_char_pos(module.inner.lo()).file;
          // Format inner attributes if available.
          if !krate.attrs.is_empty() && path == main_file {
 -            visitor.visit_attrs(&krate.attrs, ast::AttrStyle::Inner);
 +            if visitor.visit_attrs(&krate.attrs, ast::AttrStyle::Inner) {
 +                visitor.push_rewrite(module.inner, None);
 +            } else {
 +                visitor.format_separate_mod(module, &*filemap);
 +            }
          } else {
              visitor.last_pos = filemap.start_pos;
 -        }
 -        visitor.format_separate_mod(module, &*filemap);
 +            visitor.format_separate_mod(module, &*filemap);
 +        };
  
-         has_diff |= after_file(path_str, &mut visitor.buffer)?;
+         has_diff |= match after_file(path_str, &mut visitor.buffer) {
+             Ok(result) => result,
+             Err(e) => {
+                 // Create a new error with path_str to help users see which files failed
+                 let mut err_msg = path_str.to_string() + &": ".to_string() + &e.to_string();
+                 return Err(io::Error::new(e.kind(), err_msg));
+             }
+         };
  
          result.push((path_str.to_owned(), visitor.buffer));
      }