Skip to content

Commit dc3d8bf

Browse files
committed
fix: propagate errors that are triggered when writing objects (#1678)
Previously it was assumed that writing objects could never fail unless there isn't enough memory to do so. However, it turns out that some last-minute validation can always be triggered and prevent an object to be written. Now that error is propagated instead.
1 parent d15a493 commit dc3d8bf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

gix/src/repository/object.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl crate::Repository {
164164
/// we avoid writing duplicate objects using slow disks that will eventually have to be garbage collected.
165165
pub fn write_object(&self, object: impl gix_object::WriteTo) -> Result<Id<'_>, object::write::Error> {
166166
let mut buf = self.empty_reusable_buffer();
167-
object.write_to(buf.deref_mut()).expect("write to memory works");
167+
object
168+
.write_to(buf.deref_mut())
169+
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;
168170

169171
self.write_object_inner(&buf, object.kind())
170172
}

gix/tests/gix/repository/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ mod write_object {
254254
};
255255
assert_eq!(
256256
repo.write_object(commit).unwrap_err().to_string(),
257-
"TBD",
257+
"Signature name or email must not contain '<', '>' or \\n",
258258
"the actor is invalid so triggers an error when persisting it"
259259
);
260260
Ok(())

0 commit comments

Comments
 (0)