| @@ -1,25 +1,18 @@ |
| 1 | use bstr::{BString, ByteSlice}; | 1 | use bstr::{BString, ByteSlice}; |
| 2 | use git_attributes::{parse::Iter, State}; | 2 | use git_attributes::{parse::Iter, State}; |
| 3 | use quick_error::quick_error; | | |
| 4 | | 3 | |
| 5 | use crate::{MagicSignature, Pattern}; | 4 | use crate::{MagicSignature, Pattern}; |
| 6 | | 5 | |
| 7 | quick_error! { | 6 | #[derive(thiserror::Error, Debug)] |
| 8 | #[derive(Debug)] | 7 | pub enum Error { |
| 9 | pub enum Error { | 8 | #[error("Found \"{}\", which is not a valid signature", found_signature)] |
| 10 | InvalidSignature { found_signature: BString } { | 9 | InvalidSignature { found_signature: BString }, |
| 11 | display("Found \"{}\", which is not a valid signature", found_signature) | 10 | |
| 12 | } | 11 | #[error("Missing ')' at the end of pathspec magic in '{}'", pathspec)] |
| 13 | MissingClosingParenthesis { pathspec: BString } { | 12 | MissingClosingParenthesis { pathspec: BString }, |
| 14 | display("Missing ')' at the end of pathspec magic in '{}'", pathspec) | 13 | |
| 15 | } | 14 | #[error("Attribute has non-ascii characters or starts with '-': {}", attribute)] |
| 16 | // TODO: Fix error messages | 15 | InvalidAttribute { attribute: BString }, |
| 17 | InvalidAttribute(err: git_attributes::parse::Error) { | | |
| 18 | display("{}", err) | | |
| 19 | from() | | |
| 20 | source(err) | | |
| 21 | } | | |
| 22 | } | | |
| 23 | } | 16 | } |
| 24 | | 17 | |
| 25 | impl Pattern { | 18 | impl Pattern { |
| @@ -97,7 +90,14 @@ fn parse_keywords(input: &[u8]) -> Result<(MagicSignature, Vec<(BString, State)> · 71 unmodified lines |
| 97 | if let Some(attrs) = s.strip_prefix(b"attr:") { | 90 | if let Some(attrs) = s.strip_prefix(b"attr:") { |
| 98 | attributes = Iter::new(attrs.into(), 0) | 91 | attributes = Iter::new(attrs.into(), 0) |
| 99 | .map(|res| res.map(|(attr, state)| (attr.into(), state.into()))) | 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 | MagicSignature::ATTR | 101 | MagicSignature::ATTR |
| 102 | } else { | 102 | } else { |
| 103 | return Err(Error::InvalidSignature { | 103 | return Err(Error::InvalidSignature { |