Skip to content

Commit 577c54e

Browse files
committed
refactor: error handling
- find a way to reasonably keep previous semantics in downstream users
1 parent e9ac514 commit 577c54e

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

gix-mailmap/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ pub mod snapshot;
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ fn enriched_signature<'a>(
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a> From<gix_actor::SignatureRef<'a>> for Signature<'a> {
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
}

0 commit comments

Comments
 (0)