History

change(gitoxide-core)!: migrate errors to gix-error

Codex committed 2 months ago

Commit 80dca471 parent 1a9592d4 files · +26 −62Browse files

Unified · Split

4 files
  1. Cargo.lock +0 −1
  2. gitoxide-core/Cargo.toml +0 −1
  3. gitoxide-core/src/pack/create.rs +0 −19
  4. gitoxide-core/src/pack/explode.rs +26 −41
Cargo.lock+0−1
@@ -1563,7 +1563,6 @@ dependencies = [ · 1562 unmodified lines
15631563 "smallvec",
15641564 "sysinfo",
15651565 "tempfile",
1566− "thiserror 2.0.18",
15671566 "tracing",
15681567 "tracing-forest 0.2.0",
15691568 "tracing-subscriber",
gitoxide-core/Cargo.toml+0−1
@@ -58,7 +58,6 @@ gix-fsck = { version = "^0.25.1", path = "../gix-fsck" } · 57 unmodified lines
5858 gix-error-for-configuration-only = { package = "gix-error", version = "^0.3.2", path = "../gix-error", features = ["anyhow"] }
5959 serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
6060 anyhow = "1.0.102"
61−thiserror = "2.0.18"
6261 bytesize = "2.3.1"
6362 tempfile = "3.26.0"
6463 unicode-width = "0.2.2"
gitoxide-core/src/pack/create.rs+0−19
@@ -358,22 +358,3 @@ struct Statistics { · 357 unmodified lines
358358 counts: pack::data::output::count::objects::Outcome,
359359 entries: pack::data::output::entry::iter_from_counts::Outcome,
360360 }
361−
362−pub mod input_iteration {
363− use gix::{hash, traverse};
364− #[derive(Debug, thiserror::Error)]
365− pub enum Error {
366− #[error("input objects couldn't be iterated completely")]
367− Iteration(#[source] gix::Error),
368− #[error("An error occurred while reading hashes from standard input")]
369− InputLinesIo(#[from] std::io::Error),
370− #[error("Could not decode hex hash provided on standard input")]
371− HashDecode(#[from] hash::decode::Error),
372− }
373−
374− impl From<traverse::commit::simple::Error> for Error {
375− fn from(err: traverse::commit::simple::Error) -> Self {
376− Error::Iteration(err.into_error())
377− }
378− }
379−}
gitoxide-core/src/pack/explode.rs+26−41
@@ -6,6 +6,7 @@ use std::{ · 5 unmodified lines
66 };
77
88 use anyhow::{Result, anyhow};
9+use gix::error::{ErrorExt, NotFoundError, message};
910 use gix::{
1011 NestedProgress,
1112 hash::ObjectId,
@@ -64,32 +65,6 @@ impl From<SafetyCheck> for pack::index::traverse::SafetyCheck { · 52 unmodified lines
6465 }
6566 }
6667
67−#[derive(Debug, thiserror::Error)]
68−enum Error {
69− #[error("An IO error occurred while writing an object")]
70− Io(#[from] std::io::Error),
71− #[error("An object could not be written to the database")]
72− OdbWrite(#[from] loose::write::Error),
73− #[error("Failed to write {kind} object {id}")]
74− Write {
75− source: Box<dyn std::error::Error + Send + Sync>,
76− kind: object::Kind,
77− id: ObjectId,
78− },
79− #[error("Object didn't verify after right after writing it")]
80− Verify(#[source] std::io::Error),
81− #[error("{kind} object wasn't re-encoded without change")]
82− ObjectEncodeMismatch {
83− #[source]
84− source: gix::hash::verify::Error,
85− kind: object::Kind,
86− },
87− #[error("The recently written file for loose object {id} could not be found")]
88− WrittenFileMissing { id: ObjectId },
89− #[error("The recently written file for loose object {id} cold not be read")]
90− WrittenFileCorrupt { source: loose::find::Error, id: ObjectId },
91−}
92−
9368 #[expect(
9469 clippy::large_enum_variant,
9570 reason = "will be removed once `gix-error` is used consistently"
@@ -228,11 +203,15 @@ pub fn pack_or_pack_index( · 132 unmodified lines
228203 .flatten();
229204 let mut read_buf = Vec::new();
230205 move |object_kind, buf, index_entry, progress| {
231− let written_id = out.write_buf(object_kind, buf).map_err(|err| Error::Write {
232− source: err.into(),
233− kind: object_kind,
234− id: index_entry.oid,
235− })?;
206+ let written_id = out
207+ .write_buf(object_kind, buf)
208+ .map_err(|err| {
209+ err.raise(message!(
210+ "Failed to write {object_kind} object {}",
211+ index_entry.oid
212+ ))
213+ .into_error()
214+ })?;
236215 if let Err(err) = written_id.verify(&index_entry.oid) {
237216 if let object::Kind::Tree = object_kind {
238217 progress.info(format!(
@@ -240,22 +219,28 @@ pub fn pack_or_pack_index( · 1 unmodified line
240219 index_entry.oid, written_id
241220 ));
242221 } else {
243− return Err(Error::ObjectEncodeMismatch {
244− source: err,
245− kind: object_kind,
246− });
222+ return Err(err
223+ .and_raise(message!("{object_kind} object wasn't re-encoded without change"))
224+ .into_error());
247225 }
248226 }
249227 if let Some(verifier) = loose_odb.as_ref() {
250228 let obj = verifier
251229 .try_find(&written_id, &mut read_buf)
252− .map_err(|err| Error::WrittenFileCorrupt {
253− source: err,
254− id: written_id,
230+ .map_err(|err| {
231+ err.and_raise(message!(
232+ "The recently written file for loose object {written_id} could not be read"
233+ ))
234+ .into_error()
255235 })?
256− .ok_or(Error::WrittenFileMissing { id: written_id })?;
257− obj.verify_checksum(&written_id)
258− .map_err(|err| Error::Verify(std::io::Error::other(err.into_error())))?;
236+ .ok_or_else(|| {
237+ NotFoundError::new(format!(
238+ "The recently written file for loose object {written_id} could not be found"
239+ ))
240+ .raise()
241+ .into_error()
242+ })?;
243+ obj.verify_checksum(&written_id).map_err(gix::Exn::into_error)?;
259244 }
260245 Ok(())
261246 }