History

changed quickerror to thiserror (#415)

Sidney Douw committed 4 years ago

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

Unified · Split

4 files
  1. Cargo.lock +1 −1
  2. git-pathspec/Cargo.toml +1 −1
  3. git-pathspec/src/parse.rs +18 −18
  4. git-pathspec/tests/pathspec.rs +2 −3
Cargo.lock+1−1
@@ -1421,7 +1421,7 @@ dependencies = [ · 1420 unmodified lines
14211421 "bstr",
14221422 "git-attributes",
14231423 "git-glob",
1424− "quick-error",
1424+ "thiserror",
14251425 ]
14261426
14271427 [[package]]
git-pathspec/Cargo.toml+1−1
@@ -18,4 +18,4 @@ git-attributes = { version = "^0.1.0", path = "../git-attributes" } · 17 unmodified lines
1818
1919 bstr = { version = "0.2.13", default-features = false, features = ["std"]}
2020 bitflags = "1.3.2"
21−quick-error = "2.0.0"
21+thiserror = "1.0.26"
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 {
git-pathspec/tests/pathspec.rs+2−3
@@ -112,10 +112,9 @@ fn should_fail_on_whitespace_or_invalid_keywords() { · 111 unmodified lines
112112 ),
113113 (
114114 ":(attr:+someAttr)some/path",
115− Error::InvalidAttribute(git_attributes::parse::Error::AttributeName {
116− line_number: 0,
115+ Error::InvalidAttribute {
117116 attribute: BString::from("+someAttr"),
118− }),
117+ },
119118 ),
120119 (
121120 ":(top",