History

changed quickerror to thiserror (#415)

Sidney Douw committed 4 years ago

Commit 49fcab71 parent 13b7db54 files · +22 −23Browse files

Showing the changes to git-pathspec/src (1 of 4 files). Show all

Unified · Split

git-pathspec/src/parse.rs+18−18
@@ -1,25 +1,18 @@
11 use bstr::{BString, ByteSlice};
22 use git_attributes::{parse::Iter, State};
3−use quick_error::quick_error;
43
54 use crate::{MagicSignature, Pattern};
65
7−quick_error! {
8− #[derive(Debug)]
9− pub enum Error {
10− InvalidSignature { found_signature: BString } {
11− display("Found \"{}\", which is not a valid signature", found_signature)
12− }
13− MissingClosingParenthesis { pathspec: BString } {
14− display("Missing ')' at the end of pathspec magic in '{}'", pathspec)
15− }
16− // TODO: Fix error messages
17− InvalidAttribute(err: git_attributes::parse::Error) {
18− display("{}", err)
19− from()
20− source(err)
21− }
22− }
6+#[derive(thiserror::Error, Debug)]
7+pub enum Error {
8+ #[error("Found \"{}\", which is not a valid signature", found_signature)]
9+ InvalidSignature { found_signature: BString },
10+
11+ #[error("Missing ')' at the end of pathspec magic in '{}'", pathspec)]
12+ MissingClosingParenthesis { pathspec: BString },
13+
14+ #[error("Attribute has non-ascii characters or starts with '-': {}", attribute)]
15+ InvalidAttribute { attribute: BString },
2316 }
2417
2518 impl Pattern {
@@ -97,7 +90,14 @@ fn parse_keywords(input: &[u8]) -> Result<(MagicSignature, Vec<(BString, State)> · 71 unmodified lines
9790 if let Some(attrs) = s.strip_prefix(b"attr:") {
9891 attributes = Iter::new(attrs.into(), 0)
9992 .map(|res| res.map(|(attr, state)| (attr.into(), state.into())))
100− .collect::<Result<Vec<_>, _>>()?;
93+ .collect::<Result<Vec<_>, _>>()
94+ .map_err(|e| match e {
95+ git_attributes::parse::Error::AttributeName {
96+ line_number: _,
97+ attribute,
98+ } => Error::InvalidAttribute { attribute },
99+ _ => unreachable!("expecting only 'Error::AttributeName' but got {}", e),
100+ })?;
101101 MagicSignature::ATTR
102102 } else {
103103 return Err(Error::InvalidSignature {