diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-04-12 18:12:34 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-04-12 18:14:23 -0400 |
commit | c50b8b4125dc7f1181944dd92d0aca97c2450421 (patch) | |
tree | 6420424f7dcfdbd12867da5159c2a8dbf1ba1d82 /ignore/src/gitignore.rs | |
parent | 7ad23e5565e9dca308c52929571c0609c28291c6 (diff) |
Add better error messages for invalid globs.
This threads the original glob given by end users through all of the
glob parsing errors. This was slightly trickier than it might appear
because the gitignore implementation actually modifies the glob before
compiling it. So in order to get better glob error messages everywhere,
we need to track the original glob both in the glob parser and in the
higher-level abstractions in the `ignore` crate.
Fixes #444
Diffstat (limited to 'ignore/src/gitignore.rs')
-rw-r--r-- | ignore/src/gitignore.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ignore/src/gitignore.rs b/ignore/src/gitignore.rs index 4972dcd5..68655261 100644 --- a/ignore/src/gitignore.rs +++ b/ignore/src/gitignore.rs @@ -279,7 +279,12 @@ impl GitignoreBuilder { let nignore = self.globs.iter().filter(|g| !g.is_whitelist()).count(); let nwhite = self.globs.iter().filter(|g| g.is_whitelist()).count(); let set = try!( - self.builder.build().map_err(|err| Error::Glob(err.to_string()))); + self.builder.build().map_err(|err| { + Error::Glob { + glob: None, + err: err.to_string(), + } + })); Ok(Gitignore { set: set, root: self.root.clone(), @@ -420,7 +425,12 @@ impl GitignoreBuilder { GlobBuilder::new(&glob.actual) .literal_separator(literal_separator) .build() - .map_err(|err| Error::Glob(err.to_string()))); + .map_err(|err| { + Error::Glob { + glob: Some(glob.original.clone()), + err: err.kind().to_string(), + } + })); self.builder.add(parsed); self.globs.push(glob); Ok(self) |