Skip to content

Commit ea84e62

Browse files
committed
remove quick-error in favor of thiserror (#450)
1 parent ea52e4e commit ea84e62

File tree

4 files changed

+39
-64
lines changed

4 files changed

+39
-64
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ git-features = { version = "^0.22.4", path = "../git-features" }
4545
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
4646
anyhow = "1.0.42"
4747
thiserror = "1.0.34"
48-
quick-error = "2.0.0"
4948
bytesize = "1.0.1"
5049
serde_json = { version = "1.0.65", optional = true }
5150
tempfile = "3.1.0"

gitoxide-core/src/pack/create.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -372,25 +372,13 @@ struct Statistics {
372372

373373
pub mod input_iteration {
374374
use git_repository::{hash, traverse};
375-
use quick_error::quick_error;
376-
quick_error! {
377-
#[derive(Debug)]
378-
pub enum Error {
379-
Iteration(err: traverse::commit::ancestors::Error) {
380-
display("input objects couldn't be iterated completely")
381-
from()
382-
source(err)
383-
}
384-
InputLinesIo(err: std::io::Error) {
385-
display("An error occurred while reading hashes from standard input")
386-
from()
387-
source(err)
388-
}
389-
HashDecode(err: hash::decode::Error) {
390-
display("Could not decode hex hash provided on standard input")
391-
from()
392-
source(err)
393-
}
394-
}
375+
#[derive(Debug, thiserror::Error)]
376+
pub enum Error {
377+
#[error("input objects couldn't be iterated completely")]
378+
Iteration(#[from] traverse::commit::ancestors::Error),
379+
#[error("An error occurred while reading hashes from standard input")]
380+
InputLinesIo(#[from] std::io::Error),
381+
#[error("Could not decode hex hash provided on standard input")]
382+
HashDecode(#[from] hash::decode::Error),
395383
}
396384
}

gitoxide-core/src/pack/explode.rs

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use git_repository::{
1212
odb::{loose, pack, Write},
1313
Progress,
1414
};
15-
use quick_error::quick_error;
1615

1716
#[derive(Eq, PartialEq, Debug)]
1817
pub enum SafetyCheck {
@@ -69,39 +68,30 @@ impl From<SafetyCheck> for pack::index::traverse::SafetyCheck {
6968
}
7069
}
7170

72-
quick_error! {
73-
#[derive(Debug)]
74-
enum Error {
75-
Io(err: std::io::Error) {
76-
display("An IO error occurred while writing an object")
77-
source(err)
78-
from()
79-
}
80-
OdbWrite(err: loose::write::Error) {
81-
display("An object could not be written to the database")
82-
source(err)
83-
from()
84-
}
85-
Write(err: Box<dyn std::error::Error + Send + Sync>, kind: object::Kind, id: ObjectId) {
86-
display("Failed to write {} object {}", kind, id)
87-
source(&**err)
88-
}
89-
Verify(err: objs::data::verify::Error) {
90-
display("Object didn't verify after right after writing it")
91-
source(err)
92-
from()
93-
}
94-
ObjectEncodeMismatch(kind: object::Kind, actual: ObjectId, expected: ObjectId) {
95-
display("{} object {} wasn't re-encoded without change - new hash is {}", kind, expected, actual)
96-
}
97-
WrittenFileMissing(id: ObjectId) {
98-
display("The recently written file for loose object {} could not be found", id)
99-
}
100-
WrittenFileCorrupt(err: loose::find::Error, id: ObjectId) {
101-
display("The recently written file for loose object {} cold not be read", id)
102-
source(err)
103-
}
104-
}
71+
#[derive(Debug, thiserror::Error)]
72+
enum Error {
73+
#[error("An IO error occurred while writing an object")]
74+
Io(#[from] std::io::Error),
75+
#[error("An object could not be written to the database")]
76+
OdbWrite(#[from] loose::write::Error),
77+
#[error("Failed to write {kind} object {id}")]
78+
Write {
79+
source: Box<dyn std::error::Error + Send + Sync>,
80+
kind: object::Kind,
81+
id: ObjectId,
82+
},
83+
#[error("Object didn't verify after right after writing it")]
84+
Verify(#[from] objs::data::verify::Error),
85+
#[error("{kind} object {expected} wasn't re-encoded without change - new hash is {actual}")]
86+
ObjectEncodeMismatch {
87+
kind: object::Kind,
88+
actual: ObjectId,
89+
expected: ObjectId,
90+
},
91+
#[error("The recently written file for loose object {id} could not be found")]
92+
WrittenFileMissing { id: ObjectId },
93+
#[error("The recently written file for loose object {id} cold not be read")]
94+
WrittenFileCorrupt { source: loose::find::Error, id: ObjectId },
10595
}
10696

10797
#[allow(clippy::large_enum_variant)]
@@ -206,11 +196,10 @@ pub fn pack_or_pack_index(
206196
let mut read_buf = Vec::new();
207197
move |object_kind, buf, index_entry, progress| {
208198
let written_id = out.write_buf(object_kind, buf).map_err(|err| {
209-
Error::Write(
210-
Box::new(err) as Box<dyn std::error::Error + Send + Sync>,
211-
object_kind,
212-
index_entry.oid,
213-
)
199+
Error::Write{source: Box::new(err) as Box<dyn std::error::Error + Send + Sync>,
200+
kind: object_kind,
201+
id: index_entry.oid,
202+
}
214203
})?;
215204
if written_id != index_entry.oid {
216205
if let object::Kind::Tree = object_kind {
@@ -219,14 +208,14 @@ pub fn pack_or_pack_index(
219208
index_entry.oid, written_id
220209
));
221210
} else {
222-
return Err(Error::ObjectEncodeMismatch(object_kind, index_entry.oid, written_id));
211+
return Err(Error::ObjectEncodeMismatch{kind: object_kind, actual: index_entry.oid, expected:written_id});
223212
}
224213
}
225214
if let Some(verifier) = loose_odb.as_ref() {
226215
let obj = verifier
227216
.try_find(written_id, &mut read_buf)
228-
.map_err(|err| Error::WrittenFileCorrupt(err, written_id))?
229-
.ok_or(Error::WrittenFileMissing(written_id))?;
217+
.map_err(|err| Error::WrittenFileCorrupt{source:err, id:written_id})?
218+
.ok_or(Error::WrittenFileMissing{id:written_id})?;
230219
obj.verify_checksum(written_id)?;
231220
}
232221
Ok(())

0 commit comments

Comments
 (0)