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
36/// optionally name to find mappings to new names and/or emails.36/// optionally name to find mappings to new names and/or emails.
37///37///
38/// The memory layout is efficient, even though lots of small allocations are performed to store strings of emails and names.38/// 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.
39#[derive(Default, Clone, Debug, Eq, PartialEq)]46#[derive(Default, Clone, Debug, Eq, PartialEq)]
40pub struct Snapshot {47pub struct Snapshot {
41 /// Sorted by `old_email`48 /// Sorted by `old_email`
gix-mailmap/src/snapshot/mod.rs+3−3
@@ -157,17 +157,17 @@ fn enriched_signature<'a>( · 156 unmodified lines
157 (Some(new_email), Some(new_name)) => Signature {157 (Some(new_email), Some(new_name)) => Signature {
158 email: new_email.to_owned().into(),158 email: new_email.to_owned().into(),
159 name: new_name.to_owned().into(),159 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(),
161 },161 },
162 (Some(new_email), None) => Signature {162 (Some(new_email), None) => Signature {
163 email: new_email.to_owned().into(),163 email: new_email.to_owned().into(),
164 name: name.into(),164 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(),
166 },166 },
167 (None, Some(new_name)) => Signature {167 (None, Some(new_name)) => Signature {
168 email: email.into(),168 email: email.into(),
169 name: new_name.to_owned().into(),169 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(),
171 },171 },
172 (None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),172 (None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),
173 }173 }
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
29 Signature {29 Signature {
30 name: s.name.into(),30 name: s.name.into(),
31 email: s.email.into(),31 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(),
33 }33 }
34 }34 }
35}35}