History

refactor: error handling

- find a way to reasonably keep previous semantics in downstream users

Sebastian Thiel committed 1 year ago

Commit 577c54e1 parent e9ac5143 files · +11 −4Browse files

Unified · Split

3 files
  1. gix-mailmap/src/lib.rs +7 −0
  2. gix-mailmap/src/snapshot/mod.rs +3 −3
  3. gix-mailmap/src/snapshot/signature.rs +1 −1
gix-mailmap/src/lib.rs+7−0
@@ -36,6 +36,13 @@ pub mod snapshot; · 35 unmodified lines
3636 /// optionally name to find mappings to new names and/or emails.
3737 ///
3838 /// The memory layout is efficient, even though lots of small allocations are performed to store strings of emails and names.
39+///
40+/// ### Handling of invalid `SignatureRef::time`
41+///
42+/// As the `time` field in [`SignatureRef`](gix_actor::SignatureRef) as passed by the caller maybe invalid,
43+/// something that should be very rare but is possible, we decided to not expose this fallibility in the API.
44+/// Hence, the user may separately check for the correctness of `time`, which we replace with [`gix_date::Time::default()`]
45+/// in case of parse errors.
3946 #[derive(Default, Clone, Debug, Eq, PartialEq)]
4047 pub struct Snapshot {
4148 /// Sorted by `old_email`
gix-mailmap/src/snapshot/mod.rs+3−3
@@ -157,17 +157,17 @@ fn enriched_signature<'a>( · 156 unmodified lines
157157 (Some(new_email), Some(new_name)) => Signature {
158158 email: new_email.to_owned().into(),
159159 name: new_name.to_owned().into(),
160− time: gix_date::Time::from_bytes(time).expect("Time must be valid"),
160+ time: gix_date::Time::from_bytes(time).unwrap_or_default(),
161161 },
162162 (Some(new_email), None) => Signature {
163163 email: new_email.to_owned().into(),
164164 name: name.into(),
165− time: gix_date::Time::from_bytes(time).expect("Time must be valid"),
165+ time: gix_date::Time::from_bytes(time).unwrap_or_default(),
166166 },
167167 (None, Some(new_name)) => Signature {
168168 email: email.into(),
169169 name: new_name.to_owned().into(),
170− time: gix_date::Time::from_bytes(time).expect("Time must be valid"),
170+ time: gix_date::Time::from_bytes(time).unwrap_or_default(),
171171 },
172172 (None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),
173173 }
gix-mailmap/src/snapshot/signature.rs+1−1
@@ -29,7 +29,7 @@ impl<'a> From<gix_actor::SignatureRef<'a>> for Signature<'a> { · 28 unmodified lines
2929 Signature {
3030 name: s.name.into(),
3131 email: s.email.into(),
32− time: gix_date::Time::from_bytes(s.time).expect("Time must be valid"),
32+ time: gix_date::Time::from_bytes(s.time).unwrap_or_default(),
3333 }
3434 }
3535 }