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
1563 "smallvec",1563 "smallvec",
1564 "sysinfo",1564 "sysinfo",
1565 "tempfile",1565 "tempfile",
1566 "thiserror 2.0.18",
1567 "tracing",1566 "tracing",
1568 "tracing-forest 0.2.0",1567 "tracing-forest 0.2.0",
1569 "tracing-subscriber",1568 "tracing-subscriber",
gitoxide-core/Cargo.toml+0−1
@@ -58,7 +58,6 @@ gix-fsck = { version = "^0.25.1", path = "../gix-fsck" } · 57 unmodified lines
58gix-error-for-configuration-only = { package = "gix-error", version = "^0.3.2", path = "../gix-error", features = ["anyhow"] }58gix-error-for-configuration-only = { package = "gix-error", version = "^0.3.2", path = "../gix-error", features = ["anyhow"] }
59serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }59serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
60anyhow = "1.0.102"60anyhow = "1.0.102"
61thiserror = "2.0.18"
62bytesize = "2.3.1"61bytesize = "2.3.1"
63tempfile = "3.26.0"62tempfile = "3.26.0"
64unicode-width = "0.2.2"63unicode-width = "0.2.2"
gitoxide-core/src/pack/create.rs+0−19
@@ -358,22 +358,3 @@ struct Statistics { · 357 unmodified lines
358 counts: pack::data::output::count::objects::Outcome,358 counts: pack::data::output::count::objects::Outcome,
359 entries: pack::data::output::entry::iter_from_counts::Outcome,359 entries: pack::data::output::entry::iter_from_counts::Outcome,
360}360}
361
362pub 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
6};6};
7 7
8use anyhow::{Result, anyhow};8use anyhow::{Result, anyhow};
9use gix::error::{ErrorExt, NotFoundError, message};
9use gix::{10use gix::{
10 NestedProgress,11 NestedProgress,
11 hash::ObjectId,12 hash::ObjectId,
@@ -64,32 +65,6 @@ impl From<SafetyCheck> for pack::index::traverse::SafetyCheck { · 52 unmodified lines
64 }65 }
65}66}
66 67
67#[derive(Debug, thiserror::Error)]
68enum 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
93#[expect(68#[expect(
94 clippy::large_enum_variant,69 clippy::large_enum_variant,
95 reason = "will be removed once `gix-error` is used consistently"70 reason = "will be removed once `gix-error` is used consistently"
@@ -228,11 +203,15 @@ pub fn pack_or_pack_index( · 132 unmodified lines
228 .flatten();203 .flatten();
229 let mut read_buf = Vec::new();204 let mut read_buf = Vec::new();
230 move |object_kind, buf, index_entry, progress| {205 move |object_kind, buf, index_entry, progress| {
231 let written_id = out.write_buf(object_kind, buf).map_err(|err| Error::Write {206 let written_id = out
232 source: err.into(),207 .write_buf(object_kind, buf)
233 kind: object_kind,208 .map_err(|err| {
234 id: index_entry.oid,209 err.raise(message!(
235 })?;210 "Failed to write {object_kind} object {}",
211 index_entry.oid
212 ))
213 .into_error()
214 })?;
236 if let Err(err) = written_id.verify(&index_entry.oid) {215 if let Err(err) = written_id.verify(&index_entry.oid) {
237 if let object::Kind::Tree = object_kind {216 if let object::Kind::Tree = object_kind {
238 progress.info(format!(217 progress.info(format!(
@@ -240,22 +219,28 @@ pub fn pack_or_pack_index( · 1 unmodified line
240 index_entry.oid, written_id219 index_entry.oid, written_id
241 ));220 ));
242 } else {221 } else {
243 return Err(Error::ObjectEncodeMismatch {222 return Err(err
244 source: err,223 .and_raise(message!("{object_kind} object wasn't re-encoded without change"))
245 kind: object_kind,224 .into_error());
246 });
247 }225 }
248 }226 }
249 if let Some(verifier) = loose_odb.as_ref() {227 if let Some(verifier) = loose_odb.as_ref() {
250 let obj = verifier228 let obj = verifier
251 .try_find(&written_id, &mut read_buf)229 .try_find(&written_id, &mut read_buf)
252 .map_err(|err| Error::WrittenFileCorrupt {230 .map_err(|err| {
253 source: err,231 err.and_raise(message!(
254 id: written_id,232 "The recently written file for loose object {written_id} could not be read"
233 ))
234 .into_error()
255 })?235 })?
256 .ok_or(Error::WrittenFileMissing { id: written_id })?;236 .ok_or_else(|| {
257 obj.verify_checksum(&written_id)237 NotFoundError::new(format!(
258 .map_err(|err| Error::Verify(std::io::Error::other(err.into_error())))?;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)?;
259 }244 }
260 Ok(())245 Ok(())
261 }246 }