| @@ -1,25 +1,18 @@ |
| 1 | 1 | use bstr::{BString, ByteSlice}; |
| 2 | 2 | use git_attributes::{parse::Iter, State}; |
| 3 | | −use quick_error::quick_error; |
| 4 | 3 | |
| 5 | 4 | use crate::{MagicSignature, Pattern}; |
| 6 | 5 | |
| 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 }, |
| 23 | 16 | } |
| 24 | 17 | |
| 25 | 18 | impl Pattern { |
| @@ -97,7 +90,14 @@ fn parse_keywords(input: &[u8]) -> Result<(MagicSignature, Vec<(BString, State)> · 71 unmodified lines |
| 97 | 90 | if let Some(attrs) = s.strip_prefix(b"attr:") { |
| 98 | 91 | attributes = Iter::new(attrs.into(), 0) |
| 99 | 92 | .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 | + })?; |
| 101 | 101 | MagicSignature::ATTR |
| 102 | 102 | } else { |
| 103 | 103 | return Err(Error::InvalidSignature { |